1. 程式人生 > >AndroidStudio無法預覽佈局檔案問題的解決

AndroidStudio無法預覽佈局檔案問題的解決

今天寫個小demo,IDE不知道哪裡抽抽了,編寫佈局時不能預覽,報如下錯誤:

Rendering Problems The following classes could not be instantiated:- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.NoSuchMethodError: android.graphics.drawable.VectorDrawable_Delegate.nCreateTreeFromCopy(JJ)J   at android.graphics.drawable.VectorDrawable.nCreateTreeFromCopy(VectorDrawable.java:-1)   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.support.v7.widget.TintManager.getDrawable(TintManager.java:180)   at android.support.v7.widget.TintManager.getDrawable(TintManager.java:168)   at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)   at android.support.v7.widget.Toolbar.(Toolbar.java:257)   at android.support.v7.widget.Toolbar.(Toolbar.java:199)   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)   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:426)   at com.android.layoutlib.bridge.bars.BridgeActionBar.(BridgeActionBar.java:84)   at com.android.layoutlib.bridge.bars.AppCompatActionBar.(AppCompatActionBar.java:59)   at com.android.layoutlib.bridge.impl.Layout.createActionBar(Layout.java:240)   at com.android.layoutlib.bridge.impl.Layout.(Layout.java:152) Copy stack to clipboard Failed to load AppCompat ActionBar with unknown error. (2 similar errors not shown)

一通百度,雖然不知道具體為什麼,但是問題還是解決了:

在Theme.AppCompat.Light.DarkActionBar前面加上Base.  如下

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
   <!-- Customize your theme here. -->
</style>