ClassCastException: java.util.HashSet cannot be cast to java.lang.Stri

ava.lang.RuntimeException: Unable to start activity ComponentInfo{SearchActivity}: java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
	at android.app.ActivityThread.access$1100(ActivityThread.java:222)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
	at android.os.Handler.dispatchMessage (Handler.java:102)
	at android.os.Looper.loop(Looper.java:158)
	at android.app.ActivityThread.main(ActivityThread.java:7237)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
	at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:225)
	at   SearchActivity.readHistory(SearchActivity.java:332)
	at    SearchActivity.onCreate(SearchActivity.java:244)
	at android.app.Activity.performCreate(Activity.java:6876)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
	... 9 more

 I encountered a problem today. The reason is that the set used when using SharedPreferences to store, but the photo taken out with String when it is taken out is a type error.

The solution is to keep the same type when storing and retrieving

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326569863&siteId=291194637