在XML预览呈现问题:无法定位模式0

在渲染过程中更新android studioexception之后。

在渲染过程中引发exception:无法定位模式0

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) 

这是com.android.support:design:25.0.0 RecyclerView的问题

也许这个版本有一些问题。 更改版本到24.1.1解决了我的问题。

 compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:support-v13:24.1.1' compile 'com.android.support:design:24.1.1' 

如果你没有删除默认提供的gradle import,那么也改变这个

 androidTestCompile 'com.android.support:support-annotations:24.2.1' 

要么降级到v24

要么

以下既不是解决scheme也不是解决方法。

如果您只想查看PREVIEW,请在布局XML中为recyclerView添加app:layoutManager =“0”。

添加这个会抛出运行时InflateException。 所以,请在运行应用程序之前从XML布局文件中删除该属性。

只需将您的compileSdkVersion更改为24并降级依赖项即可:

 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' compile 'com.android.support:cardview-v7:24.2.1' 

而已。

临时解决scheme是降级您的项目,

  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'