错误膨胀android.support.v7.widget.Toolbar

时间:2015-09-08 18:55:06

标签: java android xml eclipse

晚上好, 我正在开发Eclipse Luna。今天我已将SDK更新为可用的最新版本,更新后所有库都出错,因此我在工作区中重新导入了所有库。一切正常,但是当我启动我的一个应用程序时,我得到了这个错误。

09-08 20:49:48.830: E/AndroidRuntime(14066): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class android.support.v7.widget.Toolbar
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2352)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2414)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread.access$900(ActivityThread.java:151)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1318)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.os.Looper.loop(Looper.java:135)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread.main(ActivityThread.java:5283)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at java.lang.reflect.Method.invoke(Native Method)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at java.lang.reflect.Method.invoke(Method.java:372)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
09-08 20:49:48.830: E/AndroidRuntime(14066): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class android.support.v7.widget.Toolbar
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at com.example.myapp.MainActivity.onCreate(MainActivity.java:73)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.Activity.performCreate(Activity.java:6865)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
09-08 20:49:48.830: E/AndroidRuntime(14066):    ... 10 more
09-08 20:49:48.830: E/AndroidRuntime(14066): Caused by: java.lang.reflect.InvocationTargetException
09-08 20:49:48.830: E/AndroidRuntime(14066):    at java.lang.reflect.Constructor.newInstance(Native Method)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.view.LayoutInflater.createView(LayoutInflater.java:607)
09-08 20:49:48.830: E/AndroidRuntime(14066):    ... 23 more
09-08 20:49:48.830: E/AndroidRuntime(14066): Caused by: java.lang.NoSuchFieldError: No static field abc_text_cursor_mtrl_alpha of type I in class Landroid/support/v7/appcompat/R$drawable; or its superclasses (declaration of 'android.support.v7.appcompat.R$drawable' appears in /data/app/com.example.myapp-2/base.apk)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.internal.widget.TintManager.<clinit>(TintManager.java:89)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.internal.widget.TintTypedArray.getTintManager(TintTypedArray.java:192)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:249)
09-08 20:49:48.830: E/AndroidRuntime(14066):    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:191)
09-08 20:49:48.830: E/AndroidRuntime(14066):    ... 26 more

在MainActivity的onCreate(扩展AppCompatActivity)中:

toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

我的布局(toolbar.xml)是

<?xml version="1.0" encoding="utf-8"?>

    <android.support.v7.widget.Toolbar 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>


And activity_main is


<?xml version="1.0" encoding="utf-8"?>

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"  
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"/>

    <FrameLayout 
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>   

    </LinearLayout>

   <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/drawer"/>   

    </android.support.v4.widget.DrawerLayout>

要解决此问题,我尝试了以下解决方案:

1-删除并重新导入android-support-v7-library到工作区(在Android 6.0上设置构建目标)

2-清理并构建

3-清理并构建工作区的所有项目

4- Put&#34; @ style&#34;在Theme.AppCompat.NoActionBar之前

5-删除并重新导入工作区中的所有项目和库

6-清理所有工作区并重新启动Eclipse

似乎没有任何作用,因为我总是得到这个错误。拜托,有人可以帮我解决一下吗?在此之前,我更新SDK和支持库,此错误不会出现。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您是否尝试在您的values / styles.xml中提供app样式:

PATH

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>