gpt4 book ai didi

Android - 字符串无法转换 bool 值 SharedPreferences

转载 作者:行者123 更新时间:2023-11-29 14:39:08 25 4
gpt4 key购买 nike

我已经调试这个问题一段时间了,但找不到在哪里将 bool 值设置为字符串或其他内容。如果需要,我可以展示更多内容,但如果您在我的堆栈跟踪中看到任何内容,请告诉我。

我的堆栈跟踪:

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

最佳答案

检查线路:

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)

看起来,您在共享首选项中将该值保存为字符串,并将其读回为导致此异常的 bool 值。

检查你适合哪种类型的值-String/Boolean,并保存和读取类似类型的值来解决这个问题。

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

关于Android - 字符串无法转换 bool 值 SharedPreferences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com