我正在尝试从字符串数组填充 listView,但我不断收到以下非常长且复杂的异常报告:
02-16 20:00:24.119: E/AndroidRuntime(17608): FATAL EXCEPTION: main
02-16 20:00:24.119: E/AndroidRuntime(17608): android.content.res.Resources$NotFoundException: Resource ID #0x7f080003 type #0x12 is not valid
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.content.res.Resources.getLayout(Resources.java:731)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.ListView.onMeasure(ListView.java:1109)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.View.measure(View.java:8172)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.View.measure(View.java:8172)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.View.measure(View.java:8172)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.View.measure(View.java:8172)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.View.measure(View.java:8172)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.ViewRoot.performTraversals(ViewRoot.java:805)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.os.Looper.loop(Looper.java:144)
02-16 20:00:24.119: E/AndroidRuntime(17608): at android.app.ActivityThread.main(ActivityThread.java:4937)
02-16 20:00:24.119: E/AndroidRuntime(17608): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 20:00:24.119: E/AndroidRuntime(17608): at java.lang.reflect.Method.invoke(Method.java:521)
02-16 20:00:24.119: E/AndroidRuntime(17608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-16 20:00:24.119: E/AndroidRuntime(17608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-16 20:00:24.119: E/AndroidRuntime(17608): at dalvik.system.NativeStart.main(Native Method)
02-16 20:00:25.789: I/Process(17608): Sending signal. PID: 17608 SIG: 9
以下是我的活动课程:
public class ArticlesActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.articles);
String[] items = {"line#1", "line#2", "line#3", "line#4"};
ListView articlesList = (ListView)findViewById(R.id.articlesList);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.article_item, items);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.article_item, R.id.articlesList, items);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.articles, R.id.articleItem, items);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.id.articleItem, items);
articlesList.setAdapter(adapter);
}
}
这是我的 ArticlesList.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/articlesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/articlesList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
这是我的 Article_item.xml:
<?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="match_parent"
android:gravity="left|right"
android:orientation="vertical" >
<TextView
android:id="@+id/articleItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<!-- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/articleItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> -->
这个问题反映了我的情况,我尝试将我的 Article_item.xml 调整为只有一个 TextView (已被注释掉),但没有任何区别。