类com.android.internal.widget.ActionBarContainer错误

时间:2016-01-24 22:29:29

标签: java android xml android-layout

我有一段可怕的时间试图找出这个问题的错误。当我尝试单击我的应用程序中的按钮时,我收到以下错误:

  

android.view.InflateException:二进制XML文件行#31:错误   inflating class com.android.internal.widget.ActionBarContainer

以下是我的清单文件:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.anders.ugym"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="23" />

    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <activity android:name=".TodoActivity" />


    </application>

</manifest>

我的styles.xml:

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

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

我的activity_register.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".RegisterActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/error_messages"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/red"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/username" />

        <EditText
            android:id="@+id/register_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="text" >

            <requestFocus />
        </EditText>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/password_label" />

        <EditText
            android:id="@+id/register_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/sign_up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:onClick="register"
            android:text="@string/sign_up_label" />
    </LinearLayout>

    <Button
        android:id="@+id/signInButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:onClick="showLogin"
        android:text="@string/already_have_an_account_label" />

</LinearLayout>

我的例外:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.anders.ugym/com.example.anders.ugym.MainActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:135)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:372)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                        Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                                                                           at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3605)
                                                                           at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3677)
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:368)
                                                                           at android.app.Activity.setContentView(Activity.java:2145)
                                                                           at com.example.anders.ugym.MainActivity.onCreate(MainActivity.java:26)
                                                                           at android.app.Activity.performCreate(Activity.java:5990)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                                        Caused by: java.lang.reflect.InvocationTargetException
                                                                           at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:607)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3605) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3677) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:368) 
                                                                           at android.app.Activity.setContentView(Activity.java:2145) 
                                                                           at com.example.anders.ugym.MainActivity.onCreate(MainActivity.java:26) 
                                                                           at android.app.Activity.performCreate(Activity.java:5990) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                                        Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13
                                                                           at android.content.res.TypedArray.getDrawable(TypedArray.java:747)
                                                                           at android.view.View.<init>(View.java:3737)
                                                                           at android.view.ViewGroup.<init>(ViewGroup.java:497)
                                                                           at android.widget.FrameLayout.<init>(FrameLayout.java:115)
                                                                           at android.widget.FrameLayout.<init>(FrameLayout.java:111)
                                                                           at android.widget.FrameLayout.<init>(FrameLayout.java:107)
                                                                           at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:60)
                                                                           at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3605) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3677) 
                                                                           at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:368) 
                                                                           at android.app.Activity.setContentView(Activity.java:2145) 
                                                                           at com.example.anders.ugym.MainActivity.onCreate(MainActivity.java:26) 
                                                                           at android.app.Activity.performCreate(Activity.java:5990) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

1 个答案:

答案 0 :(得分:1)

正如this post Neel0507

所述
  

我有同样的错误,这就是我处理它的方式。在里面   styles.xml文件,在第一个“AppTheme”风格中放置了Base of infront   Theme.AppCompat。所以它会   “Base.Theme.AppCompat.Light.DarkActionBar”。

     

在此之后,转到您的“AndroidManifest”并在您的活动中不要   使用“AppBarOverlay”。所以它会是公正的   “机器人:主题=” @风格/ AppTheme”

     

此外,在“AndroidManifest”中删除“包名”   活动名称,只需使用“.SettingsActivity”。

     

如果您有其他活动,那么不要在每个活动中定义AppTheme   活动,只需使用android:parentActivityName =“。SettingsActivity。”

     

我知道您想要一个操作栏并删除AppBarOverlay   救命。如果有效,请告诉我。

希望它有所帮助..