2013-02-15 88 views
1

我有一個微調,它通過網絡服務調用加載,它工作正常,但當我滾動它或選擇第二次它的項目崩潰的應用程序。首先點擊它工作正常。我知道這可能是一個數組長度的問題,但不能使其工作。微調滾動崩潰的應用程序

這是我的代碼:

Log.d("ArrayAdapter",""+ SpinnerData.length); 
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(abc.this,android.R.layout.simple_list_item_1, SpinnerData); 

spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
lv.setAdapter(spinnerArrayAdapter); 

SpinnerData是含有數據從服務來字符串數組。

的logcat的是這樣的:

02-15 10:40:40.350: W/System.err(992): java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0 
02-15 10:40:40.360: W/System.err(992): at java.util.Vector.elementAt(Vector.java:329) 
02-15 10:40:40.360: W/System.err(992): at org.ksoap2.serialization.SoapObject.getProperty(SoapObject.java:116) 
02-15 10:40:40.360: W/System.err(992): at ums.lovely.university.StudentPracMarsksDetails.soap(StudentPracMarsksDetails.java:216) 
02-15 10:40:40.360: W/System.err(992): at ums.lovely.university.StudentPracMarsksDetails$Search$1.run(StudentPracMarsksDetails.java:322) 
02-15 10:40:40.360: W/System.err(992): at android.os.Handler.handleCallback(Handler.java:587) 
02-15 10:40:40.360: W/System.err(992): at android.os.Handler.dispatchMessage(Handler.java:92) 
02-15 10:40:40.360: W/System.err(992): at android.os.Looper.loop(Looper.java:123) 
02-15 10:40:40.370: W/System.err(992): at android.app.ActivityThread.main(ActivityThread.java:4627) 
02-15 10:40:40.370: W/System.err(992): at java.lang.reflect.Method.invokeNative(Native Method) 
02-15 10:40:40.370: W/System.err(992): at java.lang.reflect.Method.invoke(Method.java:521) 
02-15 10:40:40.370: W/System.err(992): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
02-15 10:40:40.370: W/System.err(992): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
02-15 10:40:40.370: W/System.err(992): at dalvik.system.NativeStart.main(Native Method) 
02-15 10:40:40.370: D/The students3rfrfg4ry(992): ghsksrrsio 
02-15 10:40:40.370: D/Else The studenty(992): ghskssio 
02-15 10:40:41.130: D/AndroidRuntime(992): Shutting down VM 
02-15 10:40:41.130: W/dalvikvm(992): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
02-15 10:40:41.150: E/AndroidRuntime(992): FATAL EXCEPTION: main 
02-15 10:40:41.150: E/AndroidRuntime(992): java.lang.NullPointerException 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:329) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:325) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.AbsListView.obtainView(AbsListView.java:1315) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ListView.makeAndAddView(ListView.java:1727) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ListView.fillDown(ListView.java:652) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ListView.fillSpecific(ListView.java:1284) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.ListView.layoutChildren(ListView.java:1570) 
02-15 10:40:41.150: E/AndroidRuntime(992): at android.widget.AbsListView.onLayout(AbsListView.java:1147) 
+0

請留言日誌作爲文本/代碼.. – QAMAR 2013-02-15 06:34:14

+0

logcat更新... – 2013-02-15 06:41:48

+0

您的列表爲空 – jlopez 2013-02-15 07:16:47

回答

0

如何在onSelectedItemListener功能?
需要記住陣列長度和陣列索引。
陣列:0 ... X
,長度爲x + 1

如果還是錯誤,請嘗試更改android.R.layout.simple_list_item_1到android.R.layout.simple_spinner_item

+0

謝謝,我解決了索引問題的問題,我在spinner的索引[0]處指定了「Select」,但是這個ArrayAdapter.createViewFromResource()錯誤仍然存​​在,我的薄微調沒有得到t他認爲 – 2013-02-15 08:14:59