Reputation: 6657
My andorid app works fine in most cases but sometimes crashes when the phone rotates, i get the error log below which I don't understand. Can anyone explain why this happens?
Here is the error log :
02-22 14:44:52.175: D/AndroidRuntime(26784): Shutting down VM
02-22 14:44:52.175: W/dalvikvm(26784): threadid=1: thread exiting with uncaught exception (group=0x40e81300)
02-22 14:44:52.183: E/AndroidRuntime(26784): FATAL EXCEPTION: main
02-22 14:44:52.183: E/AndroidRuntime(26784): java.lang.IllegalArgumentException: View not attached to window manager
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:653)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:349)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:160)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.app.Dialog.dismissDialog(Dialog.java:319)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.app.Dialog.dismiss(Dialog.java:302)
02-22 14:44:52.183: E/AndroidRuntime(26784): at com.example.chartviewer.JsonActivity$getChartItems.onPostExecute(JsonActivity.java:267)
02-22 14:44:52.183: E/AndroidRuntime(26784): at com.example.chartviewer.JsonActivity$getChartItems.onPostExecute(JsonActivity.java:1)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.os.AsyncTask.finish(AsyncTask.java:631)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.os.Looper.loop(Looper.java:137)
02-22 14:44:52.183: E/AndroidRuntime(26784): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-22 14:44:52.183: E/AndroidRuntime(26784): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 14:44:52.183: E/AndroidRuntime(26784): at java.lang.reflect.Method.invoke(Method.java:511)
02-22 14:44:52.183: E/AndroidRuntime(26784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-22 14:44:52.183: E/AndroidRuntime(26784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-22 14:44:52.183: E/AndroidRuntime(26784): at dalvik.system.NativeStart.main(Native Method)
Update
Here is the code for the the onPostExecuteMethod:
//Removes the progress dialog when the data has been fetched
protected void onPostExecute(String args) {
progressDialog.dismiss();
//Shows alert dialog if data is unavailable
if(args != null && args.equals(noData)){
AlertDialog.Builder builder = new AlertDialog.Builder(JsonActivity.this);
builder.setIcon(R.drawable.artistlogo);
builder.setTitle("Musicmetric Charts");
builder.setMessage(noData);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// finishes the activity and leads back to the list of charts
JsonActivity.this.finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
Upvotes: 0
Views: 564
Reputation: 11608
to expand ashtom's answer: try to maintain device rotation by yourself:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.equals(Configuration.ORIENTATION_LANDSCAPE)){
// TODO
}else if (newConfig.equals(Configuration.ORIENTATION_PORTRAIT)){
// TODO
}
}
Upvotes: 0
Reputation: 804
These are the 2 relevant lines in your stacktrace:
com.example.chartviewer.JsonActivity$getChartItems.onPostExecute(JsonActivity.java:267)
You have implemented the onPostExcecute method of an AsyncTask. This method is dismissing a dialog:
android.app.Dialog.dismiss(Dialog.java:302)
When you rotate the device, the AsyncTask continues to run and tries to hide a dialog that isn't visible anymore.
Upvotes: 4