ANDROID 屏幕方向变化
如何在 Android 中正确处理屏幕方向更改?
谁能帮我解决这个问题吗?
我总是收到此错误:
05-12 07:20:38.223: ERROR/AndroidRuntime(410): FATAL EXCEPTION: main
05-12 07:20:38.223: ERROR/AndroidRuntime(410): java.lang.RuntimeException: Unable to destroy activity {com.loginpage/com.loginpage.MainActivity}: java.lang.NullPointerException
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3789)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.access$2400(ActivityThread.java:125)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.os.Looper.loop(Looper.java:123)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at java.lang.reflect.Method.invoke(Method.java:521)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at dalvik.system.NativeStart.main(Native Method)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): Caused by: java.lang.NullPointerException
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.loginpage.MainActivity.storePreferences(MainActivity.java:80)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.loginpage.MainActivity.onDestroy(MainActivity.java:29)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): ... 12 more
How can I properly handle screen orientation changes in android?
Can anyone help me solve this problem?
I always get this error:
05-12 07:20:38.223: ERROR/AndroidRuntime(410): FATAL EXCEPTION: main
05-12 07:20:38.223: ERROR/AndroidRuntime(410): java.lang.RuntimeException: Unable to destroy activity {com.loginpage/com.loginpage.MainActivity}: java.lang.NullPointerException
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3789)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.access$2400(ActivityThread.java:125)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.os.Looper.loop(Looper.java:123)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at java.lang.reflect.Method.invokeNative(Native Method)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at java.lang.reflect.Method.invoke(Method.java:521)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at dalvik.system.NativeStart.main(Native Method)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): Caused by: java.lang.NullPointerException
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.loginpage.MainActivity.storePreferences(MainActivity.java:80)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at com.loginpage.MainActivity.onDestroy(MainActivity.java:29)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
05-12 07:20:38.223: ERROR/AndroidRuntime(410): ... 12 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
崩溃发生在 MainActivity 的第 80 行。
为了避免重新创建您的活动,请将其添加到您的清单文件中,
并将其添加到活动中
The crash occurred at line 80 of MainActivity.
To avoid recreation of your activity add this to your manifest file
and this to the activity
将其放在
AndroidManifest.xml 中的活动声明中,如下所示:
Put this
on the declaration of the activity in the AndroidManifest.xml like this :
您应该发布代码,无论如何,堆栈跟踪会告诉您很多信息:
MainActivity.storePreferences(MainActivity.java:80) 处的 Java 空指针异常
调试/检查您的代码..
You should post the code, anyway, the stack trace tells you a lot:
Java null pointer exception at MainActivity.storePreferences(MainActivity.java:80)
Debug/check your code..