Hi. I'll try to explain the situation as clear as possible. I'll
provide all the data I can.
My problem is: I click on a checkbox in my PreferenceActivity activity
and got a Null pointer exception. I took it from the API demo app. I
also borrow LunarView and LunarThread from Lunar Lander example.
These logs were taken right after I press a button to launch my
preference Activity.
09-29 14:21:50.413: INFO/ActivityManager(76): Starting activity:
Intent { cmp=com.company.mygame/.PreferencesFromXml }
09-29 14:21:50.423: WARN/com.company.mygame.GameActivity(934): SIS
called
09-29 14:21:51.013: INFO/ActivityManager(76): Displayed activity
com.company.mygame/.PreferencesFromXml: 581 ms (total 581 ms)
//***************please notice these 2 lines. This is exactly when I
clicked on one of the checkboxes. I printed out 2 objects that might
be the culprit *********************//
09-29 14:21:52.033: ERROR/onSharedPreferenceChanged(934):
mlunarview=com.company.mygame.lunarv...@438c1448
mLunarThread=Thread[Thread-45,5,main]
09-29 14:21:52.033: ERROR/onSharedPreferenceChanged(934):
mlunarview=com.company.mygame.lunarv...@438c9930 mLunarThread=null
***************** then I suddenly got Null pointer
exception
****************************************************//
09-29 14:21:52.043: DEBUG/AndroidRuntime(934): Shutting down VM
09-29 14:21:52.043: WARN/dalvikvm(934): threadid=3: thread exiting
with uncaught exception (group=0x4001da28)
09-29 14:21:52.043: ERROR/AndroidRuntime(934): Uncaught handler:
thread main exiting due to uncaught exception
09-29 14:21:52.103: ERROR/AndroidRuntime(934):
java.lang.NullPointerException
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
com.company.mygame.GameActivity
$1.onSharedPreferenceChanged(GameActivity.java:352)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.app.ApplicationContext$SharedPreferencesImpl
$EditorImpl.commit(ApplicationContext.java:2727)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.preference.Preference.tryCommit(Preference.java:1199)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.preference.Preference.persistBoolean(Preference.java:1404)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.preference.CheckBoxPreference.setChecked(CheckBoxPreference.java:
155)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.preference.CheckBoxPreference.onClick(CheckBoxPreference.java:
143)
09-29 14:21:52.103: ERROR/AndroidRuntime(934): at
android.preference.Preference.performClick(Preference.java:811)
OK, I know you need more info, here's the content of GameActivity.java
around line 352:
OnSharedPreferenceChangeListener mOnSPListener = new
OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String
key) {
if (key.equals("sound_preference")) {
boolean soundOn =
sharedPreferences.getBoolean(key, true);
Log.e("onSharedPreferenceChanged",
"mLunarView="+mLunarView+ "
mLunarThread="+mLunarThread); //***********you can see the log
output above for this line*******//
mLunarThread.prefChangedSound(soundOn);
//***********line 352
is here*******//
} else if (key.equals("music_preference")) {
boolean musicOn =
sharedPreferences.getBoolean(key, true);
mLunarThread.prefChangedMusic(musicOn);
}
}
};
What's worse is this Null pointer won't always happen! To reproduce
this bug, I did this:
1. Launch my game. Initializing both LunarView and LunarThread.
2. Click 'Option' button to go into preference activity.
3. Click on a checkbox to turn on/off the sound or music.
4. Press back to return to title screen of my game.
5. Press back again to exit the game completely. Releasing any thread
that's running.
repeat 1-5 for three to four times then I got Null pointer when I
click on a checkbox. You can see the log above.
I'm really at a dead end now. Can experts help me please? I did
everything I can for the past 3 days.
btw this was tested on Dev Phone One and Motorola Milestone.
Thank you in advance!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en