更改活动时崩溃android.view.InflateException:二进制XML文件行#1:错误导致类<unknown>

时间:2016-02-28 22:45:09

标签: android xml crash

我在这次崩溃中遇到了困难......我正在使用api 18 一旦我点击按钮配置就会崩溃

这里是logcat:

02-28 23:30:47.497  22561-22561/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.acer.thewatcher, PID: 22561
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acer.thewatcher/com.acer.thewatcher.configuration}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2447)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:626)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.configuration.onCreate(configuration.java:35)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

和configuration.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/configuration"
    android:id="@+id/configuration">



        <Button
            android:layout_width="100dp"
            android:layout_height="33dp"
            android:layout_marginLeft="210dp"
            android:text="Internet"
            android:textSize="10dp"
            android:id="@+id/binternet"
            android:layout_marginTop="80dp" />

        <Button
            android:layout_width="100dp"
            android:layout_height="33dp"
            android:layout_marginLeft="210dp"
            android:layout_marginTop="110dp"
            android:textSize="10dp"
            android:text="Test"
            android:id="@+id/binternettest" />

    <Button
        android:layout_width="100dp"
        android:layout_height="33dp"
        android:layout_marginLeft="210dp"
        android:layout_marginTop="160dp"
        android:text="GSM"
        android:textSize="10dp"
        android:id="@+id/bgsm" />

    <Button
        android:layout_width="100dp"
        android:layout_height="33dp"
        android:layout_marginLeft="210dp"
        android:layout_marginTop="190dp"
        android:text="Test"
        android:textSize="10dp"
        android:id="@+id/bgsmtest" />

    <Button
        android:layout_width="100dp"
        android:layout_height="33dp"
        android:layout_marginLeft="210dp"
        android:layout_marginTop="250dp"
        android:text="M.Veille"
        android:textSize="10dp"
        android:id="@+id/bveille" />

    <Button
        android:layout_width="100dp"
        android:layout_height="33dp"
        android:layout_marginLeft="210dp"
        android:layout_marginTop="303dp"
        android:text="Eteindre"
        android:textSize="10dp"
        android:id="@+id/bshut" />

    <Button
        android:layout_width="100dp"
        android:layout_height="33dp"
        android:layout_marginLeft="210dp"
        android:layout_marginTop="363dp"
        android:text="Initilize"
        android:textSize="10dp"
        android:id="@+id/binitiliset" />




</RelativeLayout>
PS:我尝试了一切即将放弃......

这里的清单:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.NoActionBar">
     <activity
        android:name=".login"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustResize|stateHidden" >
        <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" >
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".localisation"
            android:label="@string/title_activity_localisation" >
        </activity>
        <activity
            android:name=".configuration"
            android:label="@string/title_activity_configuration" >
        </activity>
    </application>

更新logcat

Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.configuration.onCreate(configuration.java:35)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.OutOfMemoryError
            at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:694)
            at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:519)
            at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:889)
            at android.content.res.Resources.loadDrawable(Resources.java:3382)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
            at android.view.View.<init>(View.java:3715)
            at android.view.View.<init>(View.java:3645)
            at android.view.ViewGroup.<init>(ViewGroup.java:474)
            at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.acer.thewatcher.configuration.onCreate(configuration.java:35)
            at android.app.Activity.performCreate(Activity.java:5541)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5692)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

第二个堆栈跟踪中有一个OOM异常。我看到你有一个&#34;配置&#34;可绘制的,什么是可绘制的?它是一个非常大的图像,可能会导致OOM异常吗?尝试删除drawable(android:background =&#34; @ drawable / configuration&#34;)以查看是否能解决问题;如果是这样,请使用较小的位图作为背景,或者使用XML drawable。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/configuration"  <--- remove this
    android:id="@+id/configuration">