我在使用API24和API25(Android Nougat)的Android设备上创建Runnable()时遇到了一些问题。总之,我正在尝试做类似的事情:
MyAsyncTask myTask = new MyAsyncTask();
myTask.executeTask(new AsyncTaskListener() {
@Override
public void onTaskFinished(Object result) {
try {
Runnable r = new Runnable() {
@Override
public void run() {
Log.i("Test", "Hello Runnable");
}
};
}
catch (Exception ex) {
Log.i("Test", "Exception");
}
}
});
在早于24的API上,一切正常,但在API24和25上,我正在捕捉异常:
Attempt to invoke virtual method 'boolean java.lang.Class.isAnonymousClass()' on a null object reference
任何想法,提示或建议如何解决这个问题?
修改
完整的callstack:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isAnonymousClass()' on a null object reference
at hugo.weaving.internal.Hugo.asTag(Hugo.java:97)
at hugo.weaving.internal.Hugo.asTag(Hugo.java:98)
at hugo.weaving.internal.Hugo.enterMethod(Hugo.java:71)
at hugo.weaving.internal.Hugo.ajc$inlineAccessMethod$hugo_weaving_internal_Hugo$hugo_weaving_internal_Hugo$enterMethod(Hugo.java:1)
at hugo.weaving.internal.Hugo.logAndExecute(Hugo.java:36)
at my.app.MainFragmentActivity$9$1.<init>(MainFragmentActivity.java:918)
at my.app.MainFragmentActivity$9.onTaskFinished_aroundBody2(MainFragmentActivity.java:918)
at my.app.MainFragmentActivity$9$AjcClosure3.run(MainFragmentActivity.java:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
at hugo.weaving.internal.Hugo.logAndExecute(Hugo.java:39)
at my.app.MainFragmentActivity$9.onTaskFinished(MainFragmentActivity.java:914)
at my.app.module.net.WhoIsOnlineAsyncTask.onPostExecute(WhoIsOnlineAsyncTask.java:78)
at my.app.module.net.WhoIsOnlineAsyncTask.onPostExecute(WhoIsOnlineAsyncTask.java:19)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
行:
at my.app.MainFragmentActivity$9$1.<init>(MainFragmentActivity.java:918)
指向我创建Runnable实例时的行。我没有事件执行创建Runnable。在上面的代码中,我尽可能多地删除了哪一行导致崩溃问题。