我正在写一个做很多东西的库。
情况: 在我的android项目AAA中,我包含了库XXX,并从抽象类A(位于库XXX中)派生。
当我尝试在库XXX中调用派生类时,GSON找不到类(在调试器中我可以看到正确的类 - 它之前已提供给工厂)
Gson在解决过程中以InvocationTargetException
停止。如果它是库XXX
JSON:
{
"subtext":"super subtext!!!",
"myText":"hello 1",
"id":"ff8081813cf34f79013cf34fba750001",
"myAAA":false,
"version":0
}
代码:
// code to invoke (in library XXX)
public static A fromJson(String gsonString,
Class clazz) {
A myAbstractClass = null; // A1 is a subclass of A
try {
Gson gson = new Gson();
myAbstractClass = gson.fromJson(gsonString, clazz);
} catch (Exception e) {
}
return myAbstractClass;
}
我该如何解决这个问题?
编辑:stacktrace
02-19 17:58:24.442: E/AndroidRuntime(4463): FATAL EXCEPTION: main
02-19 17:58:24.442: E/AndroidRuntime(4463): java.lang.StackOverflowError
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:371)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:355)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:117)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
02-19 17:58:24.442: E/AndroidRuntime(4463): at com.google.gson.Gson.getAdapter(Gson.java:353)