AndroidStudio自定义View无法预览的问题解决

有时候会遇到无法预览的问题

java.lang.NoSuchMethodError: android.graphics.drawable.VectorDrawable_Delegate.nCreateTreeFromCopy(JJ)J
    at android.graphics.drawable.VectorDrawable.nCreateTreeFromCopy(VectorDrawable.java)
    at android.graphics.drawable.VectorDrawable.access$400(VectorDrawable.java:204)
    at android.graphics.drawable.VectorDrawable$VectorDrawableState.createNativeTreeFromCopy(VectorDrawable.java:837)
    at android.graphics.drawable.VectorDrawable$VectorDrawableState.(VectorDrawable.java:812)
    at android.graphics.drawable.VectorDrawable.mutate(VectorDrawable.java:268)
    at android.graphics.drawable.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:374)
    at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1224)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1197)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:315)
    at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:681)
    at android.widget.ProgressBar.(ProgressBar.java:318)
    at android.widget.ProgressBar.(ProgressBar.java:268)
    at android.widget.ProgressBar.(ProgressBar.java:264)
    at android.widget.ProgressBar.(ProgressBar.java:260)
    at q.rorbin.qrefreshlayout.HeaderView.initContentView(HeaderView.java:116)
    at q.rorbin.qrefreshlayout.HeaderView.init(HeaderView.java:103)
    at q.rorbin.qrefreshlayout.HeaderView.(HeaderView.java:39)
    at q.rorbin.qrefreshlayout.HeaderView.(HeaderView.java:34)
    at q.rorbin.qrefreshlayout.HeaderView.(HeaderView.java:30)
    at q.rorbin.qrefreshlayout.QRefreshLayout.createDefaultHeaderView(QRefreshLayout.java:123)
    at q.rorbin.qrefreshlayout.QRefreshLayout.onFinishInflate(QRefreshLayout.java:90)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:867)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:317)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:520)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:508)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:508)
    at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:75)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:620)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:617)
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:371)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:617)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:639)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:654)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:596)
    at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:591)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
    at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
    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)

我的解决办法如下:

解决办法一:

一般情况下,排除布局错误文件错误的问题,所有布局仍无法预览,更新编译工具SDK就可以解决

解决办法二:

修改APP的主题,我试了没用,可以参考一下

解决办法三:

AndroidStudio自定义View无法预览的问题解决_第1张图片

改成,可以实现预览,但是效果不佳

如下

AndroidStudio自定义View无法预览的问题解决_第2张图片

总结:把API版本改成24以外的版本都可以

你可能感兴趣的:(安卓)