私はflick_level_number
好みに合わせて保存しようとしています。
しかし、これは機能しません:(どうすればそれを保存できflick_level_number
ますか?
そしてどうすればonCreateを読むことができますか?
public void selectSensibility(int level_number){
switch (level_number) {
case 0:
flick_width_sensibility = 0.2f;
flick_height_sensibility = 0.3f;
flick_level_number = 0;
break;
case 1:
flick_width_sensibility = 0.4f;
flick_height_sensibility = 0.2f;
flick_level_number = 1;
break;
case 2:
flick_width_sensibility = 0.6f;
flick_height_sensibility = 0.15f;
flick_level_number = 2;
break;
}
//Here, I want to store `flick_level_number` to Preference
Editor editor = sharedPref.edit();
editor.putString(
"flick_level_number", writeEditText.getText().toString());
editor.commit();
}
LogCat
08-14 22:05:34.102: E/AndroidRuntime(9413): FATAL EXCEPTION: main
08-14 22:05:34.102: E/AndroidRuntime(9413): java.lang.NullPointerException
08-14 22:05:34.102: E/AndroidRuntime(9413): at com.sample.MainActivity.selectSensibility(MainActivity.java:240)
08-14 22:05:34.102: E/AndroidRuntime(9413): at com.sample.MainActivity$2.onClick(MainActivity.java:270)
08-14 22:05:34.102: E/AndroidRuntime(9413): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:980)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.widget.AbsListView.performItemClick(AbsListView.java:1150)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.widget.ListView.performItemClick(ListView.java:4397)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2985)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.widget.AbsListView$1.run(AbsListView.java:3671)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.os.Handler.handleCallback(Handler.java:615)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.os.Looper.loop(Looper.java:155)
08-14 22:05:34.102: E/AndroidRuntime(9413): at android.app.ActivityThread.main(ActivityThread.java:5511)
08-14 22:05:34.102: E/AndroidRuntime(9413): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 22:05:34.102: E/AndroidRuntime(9413): at java.lang.reflect.Method.invoke(Method.java:511)
08-14 22:05:34.102: E/AndroidRuntime(9413): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
08-14 22:05:34.102: E/AndroidRuntime(9413): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
08-14 22:05:34.102: E/AndroidRuntime(9413): at dalvik.system.NativeStart.main(Native Method)