Spinner无法从WebService填充数据

时间:2013-09-14 12:08:32

标签: java android android-asynctask spinner

我试图从asynctask方法中获取数据库中的数据 但这个错误发生在我的代码中,知道我在其他活动中使用的相同代码,一切都很好。这是Logcat

09-14 15:01:50.575: D/GestureDetector(16972): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
09-14 15:01:50.705: D/AbsListView(16972): Get MotionRecognitionManager
09-14 15:01:52.375: D/AndroidRuntime(16972): Shutting down VM
09-14 15:01:52.375: W/dalvikvm(16972): threadid=1: thread exiting with uncaught exception (group=0x40f522a0)
09-14 15:01:52.380: E/AndroidRuntime(16972): FATAL EXCEPTION: main
09-14 15:01:52.380: E/AndroidRuntime(16972): java.lang.NullPointerException
09-14 15:01:52.380: E/AndroidRuntime(16972):    at com.example.t.m.r.AddNewAttendActivity$GetClasses.onPostExecute(AddNewAttendActivity.java:218)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at com.example.t.m.r.AddNewAttendActivity$GetClasses.onPostExecute(AddNewAttendActivity.java:1)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.os.AsyncTask.finish(AsyncTask.java:631)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.os.Looper.loop(Looper.java:137)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at android.app.ActivityThread.main(ActivityThread.java:4898)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at java.lang.reflect.Method.invokeNative(Native Method)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at java.lang.reflect.Method.invoke(Method.java:511)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-14 15:01:52.380: E/AndroidRuntime(16972):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:3)

您是否在onPostExecute中初始化了Spinner?

第218行之前的

spin_class.setAdapter(adapter1);

你必须在 onPostExecute 中对它进行初始化,因为你在AsycnTask中,而不是主线程!