1

我一直在调试这个问题,但我找不到将布尔值设置为字符串或其他什么的位置。如果需要,我可以展示更多内容,但如果您在我的堆栈跟踪中看到任何内容,请告诉我。

我的堆栈跟踪:

08-13 21:25:14.685: D/SensorManager(10583): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41fc5a08
08-13 21:25:14.685: D/Sensors(10583): Remain listener = Sending .. normal delay 200ms
08-13 21:25:14.685: I/Sensors(10583): sendDelay --- 200000000
08-13 21:25:14.685: D/SensorManager(10583): JNI - sendDelay
08-13 21:25:14.685: I/SensorManager(10583): Set normal delay = true
08-13 21:25:14.685: D/SensorManager(10583): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41fd3b80
08-13 21:25:14.700: W/IInputConnectionWrapper(10583): getSelectedText on inactive InputConnection
08-13 21:25:14.700: W/IInputConnectionWrapper(10583): getTextBeforeCursor on inactive InputConnection
08-13 21:25:14.700: W/IInputConnectionWrapper(10583): getTextAfterCursor on inactive InputConnection
08-13 21:25:14.720: W/IInputConnectionWrapper(10583): getSelectedText on inactive InputConnection
08-13 21:25:14.720: W/IInputConnectionWrapper(10583): setComposingText on inactive InputConnection
08-13 21:25:14.745: W/IInputConnectionWrapper(10583): getExtractedText on inactive InputConnection
08-13 21:25:18.870: D/SensorManager(10583): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41fd3b80
08-13 21:25:18.870: D/Sensors(10583): Remain listener = Sending .. normal delay 200ms
08-13 21:25:18.870: I/Sensors(10583): sendDelay --- 200000000
08-13 21:25:18.870: D/SensorManager(10583): JNI - sendDelay
08-13 21:25:18.870: I/SensorManager(10583): Set normal delay = true
08-13 21:25:18.870: D/SensorManager(10583): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41fcc0c8
08-13 21:25:18.890: W/IInputConnectionWrapper(10583): getSelectedText on inactive InputConnection
08-13 21:25:18.890: W/IInputConnectionWrapper(10583): getTextBeforeCursor on inactive InputConnection
08-13 21:25:18.890: W/IInputConnectionWrapper(10583): getTextAfterCursor on inactive InputConnection
08-13 21:25:18.915: W/IInputConnectionWrapper(10583): getSelectedText on inactive InputConnection
08-13 21:25:18.915: W/IInputConnectionWrapper(10583): setComposingText on inactive InputConnection
08-13 21:25:18.940: W/IInputConnectionWrapper(10583): getExtractedText on inactive InputConnection
08-13 21:25:23.970: D/GestureDetector(10583): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
08-13 21:25:23.975: I/System.out(10583): To
08-13 21:25:24.265: D/dalvikvm(10583): GC_CONCURRENT freed 337K, 7% free 12783K/13639K, paused 2ms+13ms, total 26ms
08-13 21:25:25.800: D/dalvikvm(10583): GC_CONCURRENT freed 330K, 7% free 12931K/13831K, paused 2ms+12ms, total 23ms
08-13 21:25:28.900: D/GestureDetector(10583): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
08-13 21:25:29.505: D/GestureDetector(10583): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
08-13 21:25:29.665: D/SensorManager(10583): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41fcc0c8
08-13 21:25:29.665: D/Sensors(10583): Remain listener = Sending .. normal delay 200ms
08-13 21:25:29.665: I/Sensors(10583): sendDelay --- 200000000
08-13 21:25:29.665: D/SensorManager(10583): JNI - sendDelay
08-13 21:25:29.665: I/SensorManager(10583): Set normal delay = true
08-13 21:25:29.760: W/IInputConnectionWrapper(10583): getSelectedText on inactive InputConnection
08-13 21:25:29.760: W/IInputConnectionWrapper(10583): setComposingText on inactive InputConnection
08-13 21:25:29.760: W/IInputConnectionWrapper(10583): getExtractedText on inactive InputConnection
08-13 21:25:31.010: D/AbsListView(10583): Get MotionRecognitionManager
08-13 21:25:31.690: D/GestureDetector(10583): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
08-13 21:25:31.890: D/AbsListView(10583): Get MotionRecognitionManager
08-13 21:25:31.895: D/AbsListView(10583): Get MotionRecognitionManager
08-13 21:25:31.905: D/AndroidRuntime(10583): Shutting down VM
08-13 21:25:31.905: W/dalvikvm(10583): threadid=1: thread exiting with uncaught exception (group=0x413782a0)
08-13 21:25:31.910: E/AndroidRuntime(10583): FATAL EXCEPTION: main
08-13 21:25:31.910: E/AndroidRuntime(10583): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordan.dictation/com.jordan.dictation.Settings_ActivityBH}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
 08-13 21:25:31.910: E/AndroidRuntime(10583):   at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.os.Looper.loop(Looper.java:137)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread.main(ActivityThread.java:4898)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at java.lang.reflect.Method.invokeNative(Native Method)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at java.lang.reflect.Method.invoke(Method.java:511)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at dalvik.system.NativeStart.main(Native Method)
08-13 21:25:31.910: E/AndroidRuntime(10583): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:242)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.Preference.getPersistedBoolean(Preference.java:1630)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.TwoStatePreference.onSetInitialValue(TwoStatePreference.java:184)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.Preference.dispatchSetInitialValue(Preference.java:1315)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.Preference.onAttachedToHierarchy(Preference.java:1127)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:97)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:38)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.GenericInflater.rInflate(GenericInflater.java:488)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.GenericInflater.inflate(GenericInflater.java:326)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.GenericInflater.inflate(GenericInflater.java:263)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:269)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:305)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at com.jordan.dictation.Settings_ActivityAH.onCreate(Settings_ActivityAH.java:20)
 08-13 21:25:31.910: E/AndroidRuntime(10583):   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:796)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.BackStackRecord.run(BackStackRecord.java:635)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.Activity.performStart(Activity.java:5200)
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
08-13 21:25:31.910: E/AndroidRuntime(10583):    ... 11 more
08-13 21:25:31.925: D/dalvikvm(10583): GC_CONCURRENT freed 301K, 6% free 13073K/13895K, paused 2ms+4ms, total 15ms
08-13 21:25:31.925: D/AbsListView(10583): [unregisterDoubleTapMotionListener]
08-13 21:25:31.925: I/MotionRecognitionManager(10583):   .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@4209b458
08-13 21:25:50.045: I/Process(10583): Sending signal. PID: 10583 SIG: 9
4

3 回答 3

6

检查线路:

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
08-13 21:25:31.910: E/AndroidRuntime(10583):    at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:242)

看起来,您将值保存为共享首选项中的字符串并将其作为布尔值读回,这会导致此异常。

检查哪种值 -String/Boolean 适合您并保存和读取类似类型的值以解决此问题。

就像,当您将字符串值保存在 Shared Prefrences 中时,将其作为字符串读回。或者,如果您需要将值读取为 Boolean ,请将其另存为 Boolean 。

于 2013-08-14T04:59:26.427 回答
2

如果您保存了具有要存储的密钥等的“共享首选项”,这些密钥使用“字符串”值,那么稍后您在需求更改后为“CheckBoxPreference”使用相同的密钥。

在这种情况下,您必须从手机中为您的应用删除 sharedPreferences。因为之前存储的 value 是 String,现在 key 用于存储 Boolean。

于 2014-12-05T13:36:46.183 回答
0

您必须在 Shared Prefs 中传递一个值并将其设置为布尔类型,但将该值作为字符串传递。我的意思是你必须像这样传递真或假——“真”,你需要像这样传递它——真的。

于 2013-08-14T04:45:55.650 回答