旋转时Android应用程序崩溃

时间:2012-09-25 07:31:02

标签: android android-layout rotation android-asynctask orientation

我将以下代码放在manifest.xml中

<activity android:name="CPohonApp" android:configChanges="keyboardHidden|orientation"></activity>

这是我活动中的代码

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

但是当我旋转时App仍会崩溃。

为什么会这样?

我使用Android 2.3.3 API 10

谢谢

修改

这是我的日志猫

09-25 14:36:31.351: E/AndroidRuntime(334): FATAL EXCEPTION: main
09-25 14:36:31.351: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.hdte.sawit/org.hdte.sawit.pohon.CPohonApp}: java.lang.NullPointerException
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.access$1600(ActivityThread.java:117)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-25 14:36:31.351: E/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method)
09-25 14:36:31.351: E/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:507)
09-25 14:36:31.351: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-25 14:36:31.351: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-25 14:36:31.351: E/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method)
09-25 14:36:31.351: E/AndroidRuntime(334): Caused by: java.lang.NullPointerException
09-25 14:36:31.351: E/AndroidRuntime(334):  at org.hdte.sawit.pohon.CPohonApp.createDialogSend(CPohonApp.java:277)
09-25 14:36:31.351: E/AndroidRuntime(334):  at org.hdte.sawit.pohon.CPohonApp.onCreateDialog(CPohonApp.java:299)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.Activity.onCreateDialog(Activity.java:2482)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.Activity.createDialog(Activity.java:882)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.Activity.restoreManagedDialogs(Activity.java:871)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.Activity.performRestoreInstanceState(Activity.java:817)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
09-25 14:36:31.351: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1625)
09-25 14:36:31.351: E/AndroidRuntime(334):  ... 12 more

3 个答案:

答案 0 :(得分:1)

你应该点(。)引导你的活动名称。

<activity android:name=".CPohonApp" android:configChanges="keyboardHidden|orientation"></activity>

或者在android清单文件中声明它时,将完整的包名与您的活动名称一起使用。

<activity android:name="yourpackagename.CPohonApp" android:configChanges="keyboardHidden|orientation"></activity>

答案 1 :(得分:0)

在每个活动代码中使用

<activity android:name=".example"  android:configChanges="orientation|keyboardHidden"/>

答案 2 :(得分:0)

在清单

中添加此代码
android:configChanges="orientation|keyboardHidden|screenSize"

完整代码示例

 <activity
        android:name=".your activity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name" >
    </activity>