2

I'm working on a app in Android Studio. When i create a new blank activity, by default there is this line in the content_main.xml

app:layout_behavior="@string/appbar_scrolling_view_behavior"

This line destroys me Layout Preview. Happened after updaten from 1.2 to 1.4 To run the app on a device or emulator works just fine.

And i'll get this NullPointerException in the Event log

null
java.lang.NullPointerException
    at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel.hasAlphaChannel(AndroidDesignerEditorPanel.java:1386)
    at com.android.tools.idea.rendering.multi.RenderPreview.createErrorThumbnail(RenderPreview.java:769)
    at com.android.tools.idea.rendering.multi.RenderPreview.tryRenderSync(RenderPreview.java:606)
    at com.android.tools.idea.rendering.multi.RenderPreview.renderSync(RenderPreview.java:531)
    at com.android.tools.idea.rendering.multi.RenderPreviewManager$3.run(RenderPreviewManager.java:1382)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.intellij.util.concurrency.QueueProcessor$RunnableConsumer.consume(QueueProcessor.java:298)
    at com.intellij.util.concurrency.QueueProcessor$RunnableConsumer.consume(QueueProcessor.java:295)
    at com.intellij.util.concurrency.QueueProcessor$2$1.run(QueueProcessor.java:110)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.concurrency.QueueProcessor$2.consume(QueueProcessor.java:107)
    at com.intellij.util.concurrency.QueueProcessor$2.consume(QueueProcessor.java:104)
    at com.intellij.util.concurrency.QueueProcessor$3$1.run(QueueProcessor.java:215)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.concurrency.QueueProcessor$3.run(QueueProcessor.java:212)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)

Also i get in the Preview the following Error Message, on API 19, not on API 22.

Rendering Problems The graphics preview in the layout editor may not be accurate: 
- PorterDuff Color Filters are not supported.

I cleaned and rebuild the Project, also reinstalled the SDK

What impact has this line of code in the xml file?

Marian
  • 69
  • 6
  • @Marian Any updates on this topic? I updated Android Studio to 1.4 today and created a new project. I am currently only creating the layouts and I'm having the same issue :/ I believe it might be related to my layout which is not being rendered, but I have nothing more on it than a RelativeLayout, ViewPager and a Button. – Edison Spencer Oct 11 '15 at 18:21

2 Answers2

2

Solution was way too simple! That little bugger was causing my Exception. tools:showIn="@layout/lay_main" It should refer obviously to tools:showIn="@layout/lay_main.xml" That problem caused me too many hours and the outcome i learned from it is nearly zero. Don't know if i was cause of that error or Android Studio

UPDATE: I just created a new Project and i've to had "xml"all the time to make the rendering work.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_test" tools:context="com.mathlife.mathlife.calculator.Test">

</RelativeLayout>

That is just a new project. If i ad xml to tools:showIn, the rendering works fine! No idea what causing this.

Marian
  • 69
  • 6
0

After taking a break and returning, I managed to solve this issue, even though I understand it might not be the solution for you.

In my case, as I said on the comment previously, one of the components I had on my layout was the ViewPager element. However, I has declaring it like this:

<ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

I declared like this since I was using API +14, so it did not occur to me what I was doing wrong (because I did not see the need to use the support library). And Android Studio did not warn me as well. Only after multiple restarts, did it tell me that ViewPager was not recognized, so I decided to declare it in the layout as expected:

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

After making this change and pressing the Refresh button, it rendered the layout as expected and no other error was found in the project.

Hope it might have helped somehow. If not for you, for another person who might stumble upon this topic.

Edison Spencer
  • 491
  • 1
  • 9
  • 24
  • Cheers for that. But my solution for my problem was much simpler. Don't know if i did that or Android Studio – Marian Oct 12 '15 at 11:05