0

Today, I found my program has different unknown error in emulator and my phone. Because I don't have any idea about it, so can anyone give me some hints?

In my program, it exist the following code:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Case 1: The program is running in emulator

It can run normally, until I changed the screen orientation. I had to debug. I found that it throw error because some value changed to null after orientation.

following is the logcat:

04-25 22:04:35.378: W/dalvikvm(520): threadid=23: thread exiting with uncaught exception (group=0x4001aa28)

04-25 22:04:35.378: E/AndroidRuntime(520): Uncaught handler: thread Thread-15 exiting due to uncaught exception

04-25 22:04:35.388: E/AndroidRuntime(520): java.lang.NullPointerException

04-25 22:04:35.388: E/AndroidRuntime(520):  at com.mytest.testit.Maincore.logicGo(Maincore.java:244)

04-25 22:04:35.388: E/AndroidRuntime(520):  at com.mytest.testit.Maincore.run(Maincore.java:325)

04-25 22:04:35.388: E/AndroidRuntime(520):  at java.lang.Thread.run(Thread.java:1060)

04-25 22:04:35.398: I/dalvikvm(520): threadid=7: reacting to signal 3

04-25 22:04:35.418: I/dalvikvm(520): Wrote stack trace to '/data/anr/traces.txt'

Case 2: The program is running in my phone

It can run normally even though I rotate my phone. But if I lock and unlock the phone, the program will throw error. About this error, I don't know how to trace. It is because this problem will not appear at the emulator.

Can anyone give some hints for me?

Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
Perry
  • 116
  • 1
  • 1
  • 7
  • 1
    Please post your logcat output and the code where the exception happens. What happens when you step through in the debugger? – Simon Apr 25 '12 at 10:41
  • I checked the error. The error come from the boolean whcih change to null. Before the orientation, the value is true. – Perry Apr 25 '12 at 12:00
  • ??? you need to help us to help you. Why not post the code, the logcat even tells you which line is the problem? I can guess, but it probably won't help. My guess is to your are not initialising mDoDraw in onCreate. BTW. It's very difficult to get a boolean value to be null, unless you're using a Boolean??? – Simon Apr 25 '12 at 14:35

1 Answers1

0

When you rotate the device, the activity is re-created. Any data you want to save, you need to do so in onSaveInstanceState();

There is a good answer about it here

Community
  • 1
  • 1
David Scott
  • 1,666
  • 12
  • 22
  • Hi David, Thanks a lot! After your reply, I checked the other data. They were changed to null too. I think you are correct. Some data were destoryed. If a object cv (cv = new CV();), can I simply save the object ? or I need to save cv's value (integer, bitmap, boolean, float...many values) one by one? – Perry Apr 26 '12 at 00:21
  • You do it either way. If you want to save an object, you need to create a parcelable object, explained here: http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/ – David Scott Apr 26 '12 at 08:53