非法国家例外

时间:2013-03-28 06:23:00

标签: android arraylist android-listview android-arrayadapter

我已经实现了简单的listview,我得到了错误

03-28 11:24:58.148: E/ArrayAdapter(275): You must supply a resource ID for a TextView
03-28 11:24:58.156: D/AndroidRuntime(275): Shutting down VM
03-28 11:24:58.156: W/dalvikvm(275): threadid=1: thread exiting with uncaught exception   (group=0x4001d800)
03-28 11:24:58.249: E/AndroidRuntime(275): FATAL EXCEPTION: main
03-28 11:24:58.249: E/AndroidRuntime(275): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ListView.onMeasure(ListView.java:1109)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.View.measure(View.java:8171)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.View.measure(View.java:8171)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.View.measure(View.java:8171)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.View.measure(View.java:8171)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.View.measure(View.java:8171)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.os.Looper.loop(Looper.java:123)
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-28 11:24:58.249: E/AndroidRuntime(275):  at java.lang.reflect.Method.invokeNative(Native Method)
03-28 11:24:58.249: E/AndroidRuntime(275):  at java.lang.reflect.Method.invoke(Method.java:521)
03-28 11:24:58.249: E/AndroidRuntime(275):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-28 11:24:58.249: E/AndroidRuntime(275):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-28 11:24:58.249: E/AndroidRuntime(275):  at dalvik.system.NativeStart.main(Native Method)
03-28 11:24:58.249: E/AndroidRuntime(275): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
03-28 11:24:58.249: E/AndroidRuntime(275):  ... 29 more
03-28 11:24:58.249: E/AndroidRuntime(275): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
03-28 11:24:58.249: E/AndroidRuntime(275):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
 03-28 11:24:58.249: E/AndroidRuntime(275):     ... 29 more
03-28 11:27:32.329: I/Process(275): Sending signal. PID: 275 SIG: 9

1 个答案:

答案 0 :(得分:1)

似乎你试图将RelativeLayout传递给ArrayAdapter,它需要一个TextView。至少这是,例外情况。