其他分享
首页 > 其他分享> > 膨胀类android.widget.listview时出错

膨胀类android.widget.listview时出错

作者:互联网

我查看了许多其他人的问题和解释,但没有任何结果对我有用.我的程序的第一个活动是ListActivity,在填充其xml文件时遇到了麻烦. LogCat输出为:

08-01 08:36:17.800: E/AndroidRuntime(1935): FATAL EXCEPTION: main
08-01 08:36:17.800: E/AndroidRuntime(1935): java.lang.RuntimeException: Unable to start activity ComponentInfo{jamie.basketball.gui/jamie.basketball.gui.TeamDisplayActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.os.Looper.loop(Looper.java:123)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at java.lang.reflect.Method.invokeNative(Native Method)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at java.lang.reflect.Method.invoke(Method.java:507)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at dalvik.system.NativeStart.main(Native Method)
08-01 08:36:17.800: E/AndroidRuntime(1935): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.Activity.setContentView(Activity.java:1657)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at jamie.basketball.gui.TeamDisplayActivity.onCreate(TeamDisplayActivity.java:137)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 08:36:17.800: E/AndroidRuntime(1935):     ... 11 more
08-01 08:36:17.800: E/AndroidRuntime(1935): Caused by: java.lang.reflect.InvocationTargetException
08-01 08:36:17.800: E/AndroidRuntime(1935):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-01 08:36:17.800: E/AndroidRuntime(1935):     ... 22 more
08-01 08:36:17.800: E/AndroidRuntime(1935): Caused by: java.lang.NullPointerException
08-01 08:36:17.800: E/AndroidRuntime(1935):     at     android.content.res.AssetManager.getResourceTextArray(AssetManager.java:214)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.content.res.Resources.getTextArray(Resources.java:361)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.content.res.TypedArray.getTextArray(TypedArray.java:628)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.widget.ListView.<init>(ListView.java:168)
08-01 08:36:17.800: E/AndroidRuntime(1935):     at android.widget.ListView.<init>(ListView.java:159)
08-01 08:36:17.800: E/AndroidRuntime(1935):     ... 25 more

我不完全知道发生了什么.我已经检查了Android Manifest,第15行是< application,看来好像不是问题.我的XML文件的第15行就是< ListView.我要发布整个XML文件,以防万一其中还有其他问题.

    <RelativeLayout 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" >

        <TextView
            android:id="@+id/num_of_teams"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="@string/debug"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ListView
            android:id="@+id/@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/num_of_teams"
            android:layout_marginTop="5dp"
            android:entries="@layout/team_list_entry" >

        </ListView>

        <Button
            android:id="@+id/delete_team"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/@android:id/list"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="30dp"
            android:text="@string/delete_team" />

        <Button
            android:id="@+id/add_team"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="false"
            android:layout_alignParentTop="false"
            android:layout_below="@+id/@android:id/list"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="30dp"
            android:layout_toRightOf="@id/delete_team"
            android:text="@string/add_team" />

    </RelativeLayout>

另外,为便于记录,引用TeamDisplayActivity的第137行的堆栈跟踪仅为setContentView(R.layout.team_list_display).任何帮助都将是很棒的,我真的不确定出了什么问题.提前致谢

解决方法:

这行看起来不正确:

 android:entries="@layout/team_list_entry" 

通常我认为它被指定为

  android:entries="@array/servers" etc.

并尝试将id指定为:

android:id="@+id/list"  

标签:android-layout,listview,inflate-exception,android
来源: https://codeday.me/bug/20191101/1980293.html