2013-03-28 100 views
0

我已經實現了簡單的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 
+3

把你的代碼放在這裏... – 2013-03-28 06:25:02

+1

請把你的代碼。 – Nikhil 2013-03-28 06:25:47

回答

1

似乎您試圖將RelativeLayout的傳遞給你的ArrayAdapter,它期望一個TextView。至少這是例外情況。