Exception raised during rendering: Unable to locate mode 0

落爺英雄遲暮 提交于 2019-12-17 15:27:29

问题


After update BuildTools to version 25.0.0.

compileSdkVersion 25
buildToolsVersion "25"

I have problem with android layout preview. Now it show error:

Exception raised during rendering: Unable to locate mode 0

I tried to Clean & Rebuild project, but it doesn't work. Before update everything was good.

I know that I can go back to previous versions of BuildTools, but I want to know why it doesn't work on version 25.0.0?


Seems like it is a problem with RecyclerView

java.lang.IllegalStateException: Unable to locate mode 0
at android.view.DisplayInfo.findMode(DisplayInfo.java:458)
at android.view.DisplayInfo.getMode(DisplayInfo.java:445)
at android.view.Display.getRefreshRate(Display.java:648)
at android.support.v7.widget.RecyclerView.onAttachedToWindow(RecyclerView.java:2392)
at android.view.View.dispatchAttachedToWindow(View.java:15392)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2953)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:333)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$53(RenderTask.java:659)
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)

回答1:


This issue has been resolved, update the support library to

compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'



回答2:


It's an Annoying bug of version 25.. A Temporary solution is to downgrade your project,

 compile 'com.android.support:appcompat-v7:24.2.1'
 compile 'com.android.support:design:24.2.1'
 compile 'com.android.support:recyclerview-v7:24.2.1'



回答3:


Another temporary solution is to replace <android.support.v7.widget.RecyclerView with <RecyclerView so you can see the rendered View. When compiling, change it back to <android.support.v7.widget.RecyclerView




回答4:


The Android Support Library provides backward-compatible utility functions. Apps can use these utility functions to provide an appropriate user experience across a wide range of Android system versions.

It's a bug issue and should be fixed in the future Release of the support-design library.

  • Rendering Problems - Exception raised during rendering: Unable to locate mode 0

You should downgrade your version for Temporary Solutions .

compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:v7:25.0.1' 
compile 'com.android.support:recyclerview-v7:25.0.1' 



回答5:


To see preview I use this trick..... add app:layoutManager="0" for the recyclerView in a layout XML

But it will throw InflateException at run time. So REMOVE this property from XML layout file before running the app!




回答6:


As temp solution you can create child class of recycler view and override only onAttachedToWindow as below. Then use this class in your XML layouts

@Override
protected void onAttachedToWindow() {
    if (!isInEditMode()) {
        super.onAttachedToWindow();
    }
}

Update: starting from support library 25.0.1, fix already included in the library and issue not exist anymore



来源:https://stackoverflow.com/questions/40161934/exception-raised-during-rendering-unable-to-locate-mode-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!