1

我将以下代码放入 manifest.xml

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

这是我活动中的代码

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

但是当我旋转时应用程序仍然崩溃。

为什么会这样?

我使用 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
4

3 回答 3

1

您应该使用 Dot(.) 引导您的活动名称。

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

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

<activity android:name="yourpackagename.CPohonApp" android:configChanges="keyboardHidden|orientation"></activity>
于 2012-09-25T07:36:23.867 回答
0

在每个活动标签中使用

<activity android:name=".example"  android:configChanges="orientation|keyboardHidden"/>
于 2012-09-25T07:59:33.467 回答
0

在清单中添加此代码

android:configChanges="orientation|keyboardHidden|screenSize"

完整的代码示例

 <activity
        android:name=".your activity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name" >
    </activity>
于 2014-11-05T15:41:51.373 回答