fetching savedInstanceState values, nullpointerexception
Posted
by
Johan
on Stack Overflow
See other posts from Stack Overflow
or by Johan
Published on 2012-06-23T21:13:04Z
Indexed on
2012/06/23
21:15 UTC
Read the original article
Hit count: 148
android
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
savedInstanceState.putString("foo", "bar");
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String myString = savedInstanceState.getString("foo");
Log.i("debug", "saved data: " + myString);
}
Im trying to preserve some values in an activity, but i recieve the following error: 06-23 23:09:44.038: E/AndroidRuntime(17584): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.johanberntsson.activitytest/se.johanberntsson.activitytest.TestActivity}: java.lang.NullPointerException
What did I miss here? Thanks
© Stack Overflow or respective owner