Android Studio 3.0 中,在做页面布局时,局部预览经常会出现这样的问题:
点击下图中的链接,可以把错误信息拷贝出来
我遇到的问题如下:
java.lang.ClassNotFoundException: android.support.v4.view.TintableBackgroundView
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:181)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:56)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:214)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at com.android.tools.idea.rendering.RenderClassLoader.defineClassAndPackage(RenderClassLoader.java:177)
at com.android.tools.idea.rendering.RenderClassLoader.loadClassFromJar(RenderClassLoader.java:92)
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:171)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:56)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:214)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:500)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:254)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:215)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:218)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:336)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:155)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:225)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at com.android.layoutlib.bridge.bars.CustomBar.<init>(CustomBar.java:90)
at com.android.layoutlib.bridge.bars.NavigationBar.<init>(NavigationBar.java:52)
at com.android.layoutlib.bridge.bars.NavigationBar.<init>(NavigationBar.java:46)
at com.android.layoutlib.bridge.impl.Layout.createNavBar(Layout.java:325)
at com.android.layoutlib.bridge.impl.Layout.<init>(Layout.java:151)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:288)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
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:appcompat-v7 的版本太低了 ,我用的是24.2.1,仍然是低的,可以尝试改成26及以上的版本,即可解决该问题