我试图从 Android 上的单个选择设置中获取相应的数字,由于某种原因,它在 LogCat 中告诉我“字符串不能在 getInt 处转换为整数。当我进入分析 sharedPref 的值时mEventLanguageSelection 分配的时间。在这一点上,它说KEY_LANGUAGE_SELECTION_LIST=2
,我很确定这意味着 getInt 应该返回值 2。发生了什么?
EventsActivity.java
http://pastebin.com/85qa72bN
strings_activity_settings.xml
http://pastebin.com/LBVqpjMF
pref_general.xml
http://pastebin.com/NGcRwGhz
09-22 20:38:25.056: D/libEGL(28573): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
09-22 20:38:25.064: D/libEGL(28573): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
09-22 20:38:25.071: D/libEGL(28573): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
09-22 20:38:25.181: D/OpenGLRenderer(28573): Enabling debug mode 0
09-22 20:38:33.157: D/dalvikvm(28573): GC_CONCURRENT freed 92K, 2% free 9117K/9240K, paused 3ms+2ms, total 25ms
09-22 20:39:33.759: D/AndroidRuntime(28573): Shutting down VM
09-22 20:39:33.759: W/dalvikvm(28573): threadid=1: thread exiting with uncaught exception (group=0x41415930)
09-22 20:39:33.790: E/AndroidRuntime(28573): FATAL EXCEPTION: main
09-22 20:39:33.790: E/AndroidRuntime(28573): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.barjinx.barjinx/com.barjinx.barjinx.EventsActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.os.Looper.loop(Looper.java:137)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread.main(ActivityThread.java:5039)
09-22 20:39:33.790: E/AndroidRuntime(28573): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 20:39:33.790: E/AndroidRuntime(28573): at java.lang.reflect.Method.invoke(Method.java:511)
09-22 20:39:33.790: E/AndroidRuntime(28573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-22 20:39:33.790: E/AndroidRuntime(28573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-22 20:39:33.790: E/AndroidRuntime(28573): at dalvik.system.NativeStart.main(Native Method)
09-22 20:39:33.790: E/AndroidRuntime(28573): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.SharedPreferencesImpl.getInt(SharedPreferencesImpl.java:240)
09-22 20:39:33.790: E/AndroidRuntime(28573): at com.barjinx.barjinx.EventsActivity.onCreate(EventsActivity.java:65)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.Activity.performCreate(Activity.java:5104)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-22 20:39:33.790: E/AndroidRuntime(28573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-22 20:39:33.790: E/AndroidRuntime(28573): ... 11 more