gpt4 book ai didi

java - 是否可以捕获 java.lang.reflect.GenericSignatureFormatError?

转载 作者:行者123 更新时间:2023-12-01 19:38:27 32 4
gpt4 key购买 nike

在 try-catch block 中调用 com.google.gson.Gson.fromJson(),但它仍然会导致以下应用程序崩溃,尽管这种情况很少发生?

java.lang.reflect.GenericSignatureFormatError: 
at libcore.reflect.GenericSignatureParser.parseFieldTypeSignature (GenericSignatureParser.java:297)
at libcore.reflect.GenericSignatureParser.parseTypeArgument (GenericSignatureParser.java:374)
at libcore.reflect.GenericSignatureParser.parseOptTypeArguments (GenericSignatureParser.java:344)
at libcore.reflect.GenericSignatureParser.parseClassTypeSignature (GenericSignatureParser.java:317)
at libcore.reflect.GenericSignatureParser.parseFieldTypeSignature (GenericSignatureParser.java:289)
at libcore.reflect.GenericSignatureParser.parseForField (GenericSignatureParser.java:218)
at java.lang.reflect.Field.getGenericType (Field.java:177)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields (ReflectiveTypeAdapterFactory.java:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create (ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter (Gson.java:457)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField (ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields (ReflectiveTypeAdapterFactory.java:166)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create (ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter (Gson.java:457)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField (ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields (ReflectiveTypeAdapterFactory.java:166)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create (ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter (Gson.java:457)
at com.google.gson.Gson.fromJson (Gson.java:921)
at com.google.gson.Gson.fromJson (Gson.java:860)

有没有办法捕获 java.lang.reflect.GenericSignatureFormatError 以防止应用程序崩溃?

编辑:代码如下:

try{
...
foo = _gson.fromJson(bufferedReader, Foo.class);
...
}catch(Exception ex) {
...
}

也许我关于 catch(Exception ex) 捕获所有内容的假设是错误的。

最佳答案

洪,您可以按照以下方式处理。

try{
...
foo = _gson.fromJson(bufferedReader, Foo.class);
...
}catch(Exception ex) {
...
}
catch(Error err) {
...
}

永远记住,任何 Error 类型的错误(例如 NoClassDefFoundErrorNoSuchMethodError)永远不会在 catch(Exception ex) block 中捕获。然而,错误是无法挽回的。您可以在 Android 应用程序中显示一些弹出消息。

关于java - 是否可以捕获 java.lang.reflect.GenericSignatureFormatError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56505138/

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