膨胀班

时间:2015-10-27 04:35:48

标签: android android-inflate inflate-exception

我有问题,但我不知道它是什么。 我总是编写这段代码并且它正常工作,但这次它不起作用。

错误:

10-27 07:40:52.769: E/AndroidRuntime(1572): FATAL EXCEPTION: main 10-27 07:40:52.769: E/AndroidRuntime(1572): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Book4000eew1/com.Book4000eew1.Lessons}:
                                                    android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.os.Handler.dispatchMessage(Handler.java:99)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.os.Looper.loop(Looper.java:137)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread.main(ActivityThread.java:4424)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at java.lang.reflect.Method.invokeNative(Native Method)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at java.lang.reflect.Method.invoke(Method.java:511)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at dalvik.system.NativeStart.main(Native Method)
    10-27 07:40:52.769: E/AndroidRuntime(1572): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.Activity.setContentView(Activity.java:1835)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at com.Book4000eew1.Lessons.onCreate(Lessons.java:13)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.Activity.performCreate(Activity.java:4465)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     ... 11 more
    10-27 07:40:52.769: E/AndroidRuntime(1572): Caused by: java.lang.reflect.InvocationTargetException
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at java.lang.reflect.Constructor.constructNative(Native Method)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.LayoutInflater.createView(LayoutInflater.java:586)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     ... 23 more
    10-27 07:40:52.769: E/AndroidRuntime(1572): Caused by: java.lang.OutOfMemoryError
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.content.res.Resources.loadDrawable(Resources.java:1935)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.View.<init>(View.java:2785)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.view.ViewGroup.<init>(ViewGroup.java:385)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.widget.LinearLayout.<init>(LinearLayout.java:174)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     at android.widget.LinearLayout.<init>(LinearLayout.java:170)
    10-27 07:40:52.769: E/AndroidRuntime(1572):     ... 26 more

这是我上课的课程:

public class Lessons extends ListActivity{

    private Integer[] lessonspics={};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lessons);   


    }


}

它的xml文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/n9"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@null"
        android:dividerHeight="3dp"
        android:padding="5dp" >

    </ListView>

</LinearLayout>

有谁知道我的问题是什么???? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

Inside ListView

而非:

android:id="@android:id/list"

执行此操作:

android:id="@+id/your ID"

答案 1 :(得分:0)

您是否已将此添加到Android清单文件

<activity android:name=".Lessons" > </activity>

似乎你有list的null值应该在layout文件中定义一个listview并为它分配一个唯一的ID。

<ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@null"
        android:dividerHeight="3dp"
        android:padding="5dp" >

从Activity的onCreate方法中,找到具有相应id

的Listview
ListView list = (ListView) findViewById(R.id.list);

如果仍然无法显示更多代码,那么将尝试解决它。​​