问题描述
- android-AsyncTask更新列表
-
求助——
在AsyncTask中调用MainActivity,更新了adapter,但是LogCat给出了onPostExecture的NullPointerException,我检查了列表,里面有值,不是空的啊。AsyncTask.java
protected void onPostExecute(List<MoviesCategory> result){ super.onPostExecute(result); //Here i have Error, i cheked result it's not null. //On AsyncTask i have Constructor when i get Activity. activity.mMoviesAdapter.addCategory(result); }
Adapter.java
List<MoviesCategory> mListMovies; public void addCategory(List<MoviesCategory> list){ mListMovies.addAll(list); notifyDataSetChanged(); }
我做的更新:
更新
FATAL EXCEPTION: main java.lang.NullPointerException at uz.afishamedia.Adapter.MoviesAdapter.addCategory(MoviesAdapter.java:49) at uz.afishamedia.Utils.LoadMovies.onPostExecute(LoadMovies.java:74) at uz.afishamedia.Utils.LoadMovies.onPostExecute(LoadMovies.java:1) at android.os.AsyncTask.finish(AsyncTask.java:631) at android.os.AsyncTask.access$600(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5191) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) at dalvik.system.NativeStart.main(Native Method)
解决方案
问题出在mListMovies本来就是空的,需要对它先初始化
Adapter.java:
List<MoviesCategory> mListMovies = new ArrayList<MoviesCategory>();
解决方案二:
你的mListMovies没初始化啊。
加上这个就行了:
List<MoviesCategory> mListMovies = new ArrayList<MoviesCategory>();
时间: 2024-11-20 18:31:13