1

不知道我是不是太累了,无法再推理了,但是我遇到了一个令人讨厌的问题,即 ListActivity 找不到它的 ListView 资源。烦人,因为我在同一个应用程序的其他两个活动中以相同的方式实现了这一点。

很基础...

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/backrepeat"
    android:tileMode="repeat"
    android:orientation="vertical">
    <ListView android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/>
</LinearLayout>

活动:

setListAdapter(new ArrayAdapter<String>(this, android.R.id.list, fileList ));   

我在这里搜索过,发现其他有明显错误的帖子......有人有什么想法吗?

获取资源未找到异常

09-10 14:25:40.366: E/AndroidRuntime(2392):     android.content.res.Resources$NotFoundException: File  from xml type layout resource ID #0x102000a

谢谢!

4

2 回答 2

2

改成

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fileList )); 

查看 ArrayAdapter 的构造函数。使用适合您的那一款

http://developer.android.com/reference/android/widget/ArrayAdapter.html

例子:

String[] GENRES = new String[] {
        "Action", "Adventure", "Animation", "Children", "Comedy",
    "Documentary", "Drama",
        "Foreign", "History", "Independent", "Romance", "Sci-Fi",
    "Television", "Thriller"
    };
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, GENRES));

GENRES是字符串数组。 android.R.layout.simple_list_item_1是您列表的布局。this指活动上下文。

Android 会查找带有提及的 id 的资源。如果它没有找到你得到ResourceNotFoundException

于 2013-09-10T14:37:45.940 回答
1

你应该改变这个:

setListAdapter(new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_list_item_1,android.R.id.list, fileList ));
于 2013-09-10T14:40:30.323 回答