I defined an AsyncTask and create an instance from inside a MapView class. Everything works perfectly except when Android decides to kill the window, then when I try to re-open the activity the app crashes with a NoClassDefFoundError for my AsyncTask. I also tried making the AsyncTask class static but nothing changed.
I have tested it several times and I'm quite confident that the crash is due to the activity being killed previously.
[Update] I didn't post the stack trace because I saw nothing relevant. I've done some more tests and now I see something in the log that can be a clue:
I/ActivityManager( 144): Displayed activity com.myorg.myApp/.MyActivity: 4456 ms (total 4456 ms)
I/dalvikvm( 3413): **Rejecting re-init on previously-failed class** Lcom/myorg/myApp/MyMapView$MyAsyncTask; v=0x0
D/AndroidRuntime( 3413): Shutting down VM
W/dalvikvm( 3413): threadid=1: thread exiting with uncaught exception (group=0x400207e8)
E/AndroidRuntime( 3413): FATAL EXCEPTION: main
E/AndroidRuntime( 3413): java.lang.No开发者_JS百科ClassDefFoundError: com.myorg.myApp.MyMapView$MyAsyncTask
E/AndroidRuntime( 3413): at com.myorg.myApp.MyMapView$4.run(MyMapView.java:169)
E/AndroidRuntime( 3413): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 3413): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3413): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3413): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 3413): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3413): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3413): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 3413): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 3413): at dalvik.system.NativeStart.main(Native Method)
The line: I/dalvikvm( 3413): Rejecting re-init on previously-failed class Makes me think that it comes from a previous error but I see no other stack traces in the log or errors reported.
I solved that problem in UI Thread
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
asynTask = new LoadWebAsynTask();
asynTask.execute();
}
});
I'd need a stack trace to be sure, but I think your problem is similar to the one described in this other question.
It's not necessarily that the classloader can't find your AsyncTask class - it's that some error is thrown during the loading of the class, or during the startup of the Thread backing the AsyncTask that's preventing the classloader from loading the class.
I'd guess the WIN DEATH is causing some strange internal state that's not being checked for and is throwing the error.
精彩评论