求助——
在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>();