0

我在使用 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

任何想法,提示或建议如何解决这个问题?

编辑

完整的调用堆栈:

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。在上面的代码中,我已尽可能多地删除以找出导致崩溃问题的行。

4

0 回答 0