gpt4 book ai didi

java.lang.AssertionError : impossible Caused by: java. lang.NoSuchMethodException: 值 []

转载 作者:行者123 更新时间:2023-12-05 05:12:09 32 4
gpt4 key购买 nike

发生了什么:

  1. 我将多个对象保存在一个数组列表中,该数组列表保存在一个 gson 字符串中。
  2. 我更改对象的类(以包含更多变量和 getter/setter 方法)
  3. 现在我在尝试加载旧对象(在步骤 1 中保存)时遇到错误

需要考虑的事项:

我使用 gson/json 将数组列表存储在 android 共享首选项中。 (共享首选项适用于其他值,错误似乎是在使用 json/gson 将字符串转换为 arraylist 时)

我的代码:

    public void loadDataSavedMatches() {
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = prefs.getString("task list", null);
Type type = new TypeToken<ArrayList<TennisMatch>>() {
}.getType();
mTennisMatches = gson.fromJson(json, type);

if (mTennisMatches == null) {
mTennisMatches = new ArrayList<>();
}

Log.i("LOAD DATA", String.valueOf(mTennisMatches));
Log.i("LOAD DATA2", String.valueOf(prefs));

//hashMap


SharedPreferences hashPrefs = getSharedPreferences(HASH_MAP_SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Gson hashGson = new Gson();
String hashJson = hashPrefs.getString("hashString", null);
Type hashType = new TypeToken<HashMap<String, TennisMatch>>() {
}.getType();
item_map = hashGson.fromJson(hashJson, hashType);

if (item_map == null) {
item_map = new HashMap<String, TennisMatch>();
}

}

错误信息:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.myapp, PID: 28341
java.lang.AssertionError: impossible
at java.lang.Enum$1.create(Enum.java:45)
at java.lang.Enum$1.create(Enum.java:35)
at libcore.util.BasicLruCache.get(BasicLruCache.java:54)
at java.lang.Enum.getSharedConstants(Enum.java:211)
at java.lang.Class.getEnumConstants(Class.java:1063)
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(TypeAdapters.java:778)
at com.google.gson.internal.bind.TypeAdapters$30.create(TypeAdapters.java:817)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:853)
at com.google.gson.Gson.fromJson(Gson.java:802)
at com.android.myapp.Activity.loadDataSavedMatches(ItemMatchListActivity.java:282)
at com.android.myapp.Activity.onCreate(ItemMatchListActivity.java:87)
at android.app.Activity.performCreate(Activity.java:6102)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$1200(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NoSuchMethodException: values []
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getDeclaredMethod(Class.java:626)
at java.lang.Enum$1.create(Enum.java:41)
at java.lang.Enum$1.create(Enum.java:35) 
at libcore.util.BasicLruCache.get(BasicLruCache.java:54) 
at java.lang.Enum.getSharedConstants(Enum.java:211) 
at java.lang.Class.getEnumConstants(Class.java:1063) 
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(TypeAdapters.java:778) 
at com.google.gson.internal.bind.TypeAdapters$30.create(TypeAdapters.java:817) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) 
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) 
at com.google.gson.Gson.getAdapter(Gson.java:423) 
at com.google.gson.Gson.fromJson(Gson.java:887) 
at com.google.gson.Gson.fromJson(Gson.java:853) 
at com.google.gson.Gson.fromJson(Gson.java:802) 
at com.android.myapp.Activity.loadDataSavedMatches(ItemMatchListActivity.java:282) 
at com.android.myapp.Activity.onCreate(ItemMatchListActivity.java:87) 
at android.app.Activity.performCreate(Activity.java:6102) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
at android.app.ActivityThread.access$1200(ActivityThread.java:165) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5593) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

感谢您的帮助!

最佳答案

参见 Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum , AssertionError in Gson EnumTypeAdapter when using Proguard Obfuscationhttps://github.com/zendesk/sunshine-conversations-android/issues/93 .在 proguard-rules.pro 添加:

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

关于java.lang.AssertionError : impossible Caused by: java. lang.NoSuchMethodException: 值 [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54847976/

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