Benjamin
unread,Jul 19, 2010, 4:31:12 PM7/19/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-gson
This has been killing me all day - thanks in advance to anyone who can
take a look. Maybe i just need a fresh set of eyes. i'm just trying to
serialize and de-serialize a list of a very simple object that has one
property
GSON 1.4
This JSON String:
[{"name":"Nimbits Stats"},{"name":"TestPoints"},{"name":"My Health"},
{"name":"System"},{"name":"Aquarium"},{"name":"Nimbits_Unsorted"},
{"name":"House"},{"name":"test"},{"name":"BEN-UBSV01"}]
Is generated on server from an arraylist of objects of this class:
public class Catagory
{
private String name;
//..getters and setters
}
thusly:
Type listType = new TypeToken<List<Catagory>>() {}.getType();
retStr = gson.toJson(myarraylist, listType);
attempt to de-serialize with this (on android client):
Type listType = new TypeToken<List<Catagory>>() {}.getType();
retObj = gson.fromJson(result, listType);
results in:
07-19 20:16:34.823: ERROR/AndroidRuntime(285): FATAL EXCEPTION: main
07-19 20:16:34.823: ERROR/AndroidRuntime(285):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.nimbits.android/
com.nimbits.android.CatagoryActivity}: java.lang.NullPointerException
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2663)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.os.Looper.loop(Looper.java:123)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread.main(ActivityThread.java:4627)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
java.lang.reflect.Method.invokeNative(Native Method)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
java.lang.reflect.Method.invoke(Method.java:521)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
dalvik.system.NativeStart.main(Native Method)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): Caused by:
java.lang.NullPointerException
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
org.apache.harmony.luni.lang.reflect.ListOfTypes.length(ListOfTypes.java:
47)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
org.apache.harmony.luni.lang.reflect.ImplForType.toString(ImplForType.java:
83)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
java.lang.StringBuilder.append(StringBuilder.java:203)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:
56)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:
88)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.JsonDeserializationVisitor.visitUsingCustomHandler(JsonDeserializationVisitor.java:
76)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:98)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.JsonDeserializationContextDefault.fromJsonArray(JsonDeserializationContextDefault.java:
64)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:
49)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.Gson.fromJson(Gson.java:495)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.Gson.fromJson(Gson.java:444)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.google.gson.Gson.fromJson(Gson.java:396)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.nimbits.google.DataClient.getJSONCatagories(DataClient.java:175)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.nimbits.android.CatagoryActivity.createDB(CatagoryActivity.java:
118)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
com.nimbits.android.CatagoryActivity.onCreate(CatagoryActivity.java:
246)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2627)
07-19 20:16:34.823: ERROR/AndroidRuntime(285): ... 11 more