Note that there are some explanatory texts on larger screens.

plurals
  1. POerror on save object to bandle
    text
    copied!<p>i want to save my class when my phone have rotate. my code is:</p> <pre><code>public class MainActivity extends FragmentActivity { private MapCanvas mapCanvas = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(savedInstanceState == null) { this.mapCanvas = new MapCanvas(this); } else { this.mapCanvas = (MapCanvas)savedInstanceState.getSerializable("s"); } setContentView(this.mapCanvas); this.mapCanvas.requestFocus(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putSerializable("s", this.mapCanvas); } } </code></pre> <p>but when i rotate my phone i have get error in line <code>setContentView(this.mapCanvas);</code></p> <p>my MapCanvas is :</p> <pre><code>public class MapCanvas extends ImageView implements Serializable { private static final long serialVersionUID = 1L; .... } </code></pre> <p>my log chat is:</p> <pre><code>11-27 20:09:37.969: W/dalvikvm(14743): threadid=1: thread exiting with uncaught exception (group=0x40187560) 11-27 20:09:37.999: E/AndroidRuntime(14743): FATAL EXCEPTION: main 11-27 20:09:37.999: E/AndroidRuntime(14743): java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.pangan.yazdbakishni/ir.pangan.yazdbakishni.activities.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2844) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.access$1600(ActivityThread.java:121) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:947) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.os.Handler.dispatchMessage(Handler.java:99) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.os.Looper.loop(Looper.java:130) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.main(ActivityThread.java:3768) 11-27 20:09:37.999: E/AndroidRuntime(14743): at java.lang.reflect.Method.invokeNative(Native Method) 11-27 20:09:37.999: E/AndroidRuntime(14743): at java.lang.reflect.Method.invoke(Method.java:507) 11-27 20:09:37.999: E/AndroidRuntime(14743): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) 11-27 20:09:37.999: E/AndroidRuntime(14743): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 11-27 20:09:37.999: E/AndroidRuntime(14743): at dalvik.system.NativeStart.main(Native Method) 11-27 20:09:37.999: E/AndroidRuntime(14743): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.view.ViewGroup.addViewInner(ViewGroup.java:1976) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.view.ViewGroup.addView(ViewGroup.java:1871) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.view.ViewGroup.addView(ViewGroup.java:1851) 11-27 20:09:37.999: E/AndroidRuntime(14743): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:226) 11-27 20:09:37.999: E/AndroidRuntime(14743): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.Activity.setContentView(Activity.java:1668) 11-27 20:09:37.999: E/AndroidRuntime(14743): at ir.pangan.yazdbakishni.activities.MainActivity.onCreate(MainActivity.java:37) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 11-27 20:09:37.999: E/AndroidRuntime(14743): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 11-27 20:09:37.999: E/AndroidRuntime(14743): ... 12 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload