0

我在尝试执行以下代码时收到此错误日志:

04-14 22:46:22.789: D/onCreate(18563): EOF
04-14 22:46:22.875: D/AndroidRuntime(18563): Shutting down VM
04-14 22:46:22.875: W/dalvikvm(18563): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-14 22:46:22.976: E/AndroidRuntime(18563): FATAL EXCEPTION: main
04-14 22:46:22.976: E/AndroidRuntime(18563): android.content.res.Resources$NotFoundException: File  from xml type layout resource ID #0x102000a
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.Resources.getLayout(Resources.java:731)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.AbsListView.obtainView(AbsListView.java:1586)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ListView.makeAndAddView(ListView.java:1782)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ListView.fillDown(ListView.java:705)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ListView.fillFromTop(ListView.java:762)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.ListView.layoutChildren(ListView.java:1633)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.AbsListView.onLayout(AbsListView.java:1416)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.View.layout(View.java:7175)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.View.layout(View.java:7175)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.View.layout(View.java:7175)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.View.layout(View.java:7175)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.View.layout(View.java:7175)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.os.Looper.loop(Looper.java:130)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.app.ActivityThread.main(ActivityThread.java:3687)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at java.lang.reflect.Method.invokeNative(Native Method)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at java.lang.reflect.Method.invoke(Method.java:507)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at dalvik.system.NativeStart.main(Native Method)
04-14 22:46:22.976: E/AndroidRuntime(18563): Caused by: java.io.FileNotFoundException: 
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.AssetManager.openXmlAssetNative(Native Method)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:486)
04-14 22:46:22.976: E/AndroidRuntime(18563):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
04-14 22:46:22.976: E/AndroidRuntime(18563):    ... 34 more

这是代码。我已经更改了我正在使用的ListView的ID,所以我可以this.getListView()根据这个问题使用,因为我之前遇到过同样的问题。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_waypoint_list);
    ArrayList<String> listItems = new ArrayList<String>();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, this.getListView().getId(), listItems);
    this.setListAdapter(adapter);
//...    nothing changed here before so left away a part.
    ListView waypoint_list = this.getListView();
    waypoint_list.setOnItemClickListener(this);
    Log.d("onCreate", "EOF");
}

这是 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"
    tools:context=".WaypointList"
    android:orientation="vertical"
    android:padding="20dp" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/my_list"
        android:textSize="30sp"
        android:textColor="#FF000000" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:choiceMode="singleChoice" >

    </ListView>

</LinearLayout>

顺便提一句。该类被定义为public class MyListActivity extends ListActivity implements OnItemClickListener

现在我已将每个更改this.getListView()(ListView)this.findViewById(android.R.id.list),但它没有显示任何效果。

4

1 回答 1

-1

在这里你制作一个新的 ArrayAdapter

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, this.getListView().getId(), listItems);

作为第二个参数,您传递 ListView 的 id,而不是您应该传递您用来填充其行的资源的 id,例如:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);

您也可以为一行创建自己的布局,但是您需要创建一个my_layout.xml描述行布局的新文件并将其R.layout.my_layout 作为第二个参数

于 2013-04-15T12:09:56.720 回答