Android App keep crashing when rotating-Collection of common programming errors
I notice right now that when I rotate the phone my app crash
I added the following stack trace
the app is based on the Facebook Friend Smasher
08-27 19:18:57.616: D/AndroidRuntime(19379): Shutting down VM
08-27 19:18:57.616: W/dalvikvm(19379): threadid=1: thread exiting with uncaught exception (group=0x41a852a0)
08-27 19:18:57.636: E/AndroidRuntime(19379): FATAL EXCEPTION: main
08-27 19:18:57.636: E/AndroidRuntime(19379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebook.android.tomatosmasher/com.facebook.android.friendsmash.HomeActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3553)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.access$700(ActivityThread.java:140)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.os.Handler.dispatchMessage(Handler.java:99)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.os.Looper.loop(Looper.java:137)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-27 19:18:57.636: E/AndroidRuntime(19379): at java.lang.reflect.Method.invokeNative(Native Method)
08-27 19:18:57.636: E/AndroidRuntime(19379): at java.lang.reflect.Method.invoke(Method.java:511)
08-27 19:18:57.636: E/AndroidRuntime(19379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
08-27 19:18:57.636: E/AndroidRuntime(19379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
08-27 19:18:57.636: E/AndroidRuntime(19379): at dalvik.system.NativeStart.main(Native Method)
08-27 19:18:57.636: E/AndroidRuntime(19379): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-27 19:18:57.636: E/AndroidRuntime(19379): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.Activity.setContentView(Activity.java:1924)
08-27 19:18:57.636: E/AndroidRuntime(19379): at com.facebook.android.friendsmash.HomeActivity.onCreate(HomeActivity.java:109)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.Activity.performCreate(Activity.java:5206)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
08-27 19:18:57.636: E/AndroidRuntime(19379): ... 12 more
08-27 19:18:57.636: E/AndroidRuntime(19379): Caused by: java.lang.NullPointerException
08-27 19:18:57.636: E/AndroidRuntime(19379): at com.facebook.android.friendsmash.FBLoggedOutHomeFragment.onCreateView(FBLoggedOutHomeFragment.java:63)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
08-27 19:18:57.636: E/AndroidRuntime(19379): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
08-27 19:18:57.636: E/AndroidRuntime(19379): ... 22 more
keep crushing when rotate from hor to ver
Thanks
-
From the log you attach there is an error while inflating the HomeActivity:
08-27 19:18:57.636: E/AndroidRuntime(19379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebook.android.tomatosmasher/com.facebook.android.friendsmash.HomeActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
This happens when you rotate the phone because at that time the Activity is destroyed and recreated to allow different resources to reload…
Investigate in this direction and post some code so we can help you better.
-
Try this… Write the below lines in your manifest…
Originally posted 2013-11-27 12:26:18.