java.lang.IllegalStateException: Nesting problem

3,130 views
Skip to first unread message

Kevin

unread,
Jun 1, 2012, 2:58:35 AM6/1/12
to google-gson
Has anyone encountered an error like that shown below. What does it
mean?

05-31 22:05:04.406: W/System.err(2818):
java.lang.IllegalStateException: Nesting problem: [NONEMPTY_DOCUMENT,
NONEMPTY_OBJECT, NONEMPTY_OBJECT, NONEMPTY_ARRAY, NONEMPTY_OBJECT]
05-31 22:05:04.410: W/System.err(2818): at
com.google.gson.stream.JsonWriter.beforeValue(JsonWriter.java:550)
05-31 22:05:04.410: W/System.err(2818): at
com.google.gson.stream.JsonWriter.open(JsonWriter.java:263)
05-31 22:05:04.410: W/System.err(2818): at
com.google.gson.stream.JsonWriter.beginObject(JsonWriter.java:246)
05-31 22:05:04.414: W/System.err(2818): at
com.google.gson.Streams.write(Streams.java:129)
05-31 22:05:04.414: W/System.err(2818): at
com.google.gson.Gson.toJson(Gson.java:362)
05-31 22:05:04.414: W/System.err(2818): at
com.google.gson.Gson.toJson(Gson.java:313)
05-31 22:05:04.414: W/System.err(2818): at
com.sensorplatforms.json.JsonSensorLogger.PrintToStream(JsonSensorLogger.java:
593)
05-31 22:05:04.414: W/System.err(2818): at
com.sensorplatforms.ActionLogger.TestingService.purgeData(TestingService.java:
425)
05-31 22:05:04.414: W/System.err(2818): at
com.sensorplatforms.ActionLogger.TestingService.access
$1(TestingService.java:421)
05-31 22:05:04.414: W/System.err(2818): at
com.sensorplatforms.ActionLogger.TestingService
$2.run(TestingService.java:391)
05-31 22:05:04.414: W/System.err(2818): at
android.os.Handler.handleCallback(Handler.java:587)
05-31 22:05:04.414: W/System.err(2818): at
android.os.Handler.dispatchMessage(Handler.java:92)
05-31 22:05:04.414: W/System.err(2818): at
android.os.Looper.loop(Looper.java:130)
05-31 22:05:04.414: W/System.err(2818): at
android.app.ActivityThread.main(ActivityThread.java:3683)
05-31 22:05:04.414: W/System.err(2818): at
java.lang.reflect.Method.invokeNative(Native Method)
05-31 22:05:04.414: W/System.err(2818): at
java.lang.reflect.Method.invoke(Method.java:507)
05-31 22:05:04.414: W/System.err(2818): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-31 22:05:04.414: W/System.err(2818): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-31 22:05:04.414: W/System.err(2818): at
dalvik.system.NativeStart.main(Native Method)
05-31 22:05:04.414: I/JsonSensLogError(2818): nt1 :
[2466.013427734375, ]
05-31 22:05:04.414: I/JsonSensLogError(2818): abc1 :
[-0.47884035110473633, -0.038307227194309235, 9.27034854888916, ]

The data being sent is shown in the last two lines: "nt1" + a double +
"abc1" + three doubles.
Which should something like this: {"nt1":[203.45901],"abc1":
[0.0012217305,0.021991149,0.004886922]}

Kevin

unread,
Jun 1, 2012, 5:21:39 PM6/1/12
to google-gson
I'm continuing to see this, even though the resulting json file (after
i add a few brackets to close the arrays) is perfectly valid. The
means there isn't actually anything wrong in the syntax of the file up
to this point.
I'm using gson 2.2.1; though I have seen the same result with 1.7.

The file is a log file used to stream very long sessions of data.
Hence we use the JsonWriter class. There are two block of code which
stream a large number of objects into an array container in the json
file.

Here is the EventLog code. This is called whenever an event needs to
be logged.

public void LogEventPrivate(String name, TimerLogItem timer, String
desc) throws IOException {

double currentTime = ((double)System.currentTimeMillis())/1000; //
seconds
double time = ((currentTime - timer.getZeroTime())) ;
writer.flush();
writer.beginObject();
writer.name(timer.getName());
writer.beginArray();
writer.value(time); // Write time value
writer.endArray();
writer.name("event");
writer.beginObject();
writer.name("name").value(name);
writer.name("desc").value(desc);
writer.endObject();
writer.endObject();
}

and here is the TimerLog code, this is called for each timer tick:

public static void PrintToStreamSingle(String name, double d){
try {
writer.flush();
writer.beginObject(); <--- Fatal exception
here
writer.name(name);
writer.beginArray();
writer.value((float) d);
writer.endArray();
writer.endObject();
writer.flush();
}
catch ....

The resulting stream looks something like this:
{data:[
{
"nt1":[
15.232756614685059
]
},
{
"nt1":[
15.234862327575684
]
},
{
"nt1":[
15.241281509399414
]
},
{
"nt1":[
15.246678352355957
]
},
{
"nt1":[
15.250899314880371
]
},
{
"nt1":[
15.254889488220215
]
},
{
"nt1":[
15.259788513183594
]
},
{
"nt1":[
15.260541915893555
]
},
{
"et1":[
11.162000179290771
],
"event":{
"name":"Events",
"desc":"Text to speech utterance completed."
}
}
<----- FAULT OCCURS HERE. The remaining lines
were added to run it through a prettyprint processor
]
}



Here is the logcat result:

06-01 13:41:00.386: D/AndroidRuntime(1746): Shutting down VM
06-01 13:41:00.386: W/dalvikvm(1746): threadid=1: thread exiting with
uncaught exception (group=0x40015560)
06-01 13:41:00.398: E/AndroidRuntime(1746): FATAL EXCEPTION: main
06-01 13:41:00.398: E/AndroidRuntime(1746):
java.lang.IllegalStateException: Nesting problem: [NONEMPTY_DOCUMENT,
NONEMPTY_OBJECT, NONEMPTY_OBJECT, NONEMPTY_ARRAY, NONEMPTY_OBJECT,
NONEMPTY_OBJECT]
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.google.gson.stream.JsonWriter.beforeValue(JsonWriter.java:550)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.google.gson.stream.JsonWriter.open(JsonWriter.java:263)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.google.gson.stream.JsonWriter.beginObject(JsonWriter.java:246)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.sensorplatforms.json.JsonSensorLogger.PrintToStreamSingle(JsonSensorLogger.java:
635)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.sensorplatforms.ActionLogger.TestingService
$2.run(TestingService.java:384)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
android.os.Handler.handleCallback(Handler.java:587)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
android.os.Handler.dispatchMessage(Handler.java:92)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
android.os.Looper.loop(Looper.java:130)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
android.app.ActivityThread.main(ActivityThread.java:3683)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
java.lang.reflect.Method.invokeNative(Native Method)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
java.lang.reflect.Method.invoke(Method.java:507)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-01 13:41:00.398: E/AndroidRuntime(1746): at
dalvik.system.NativeStart.main(Native Method)

Kevin

unread,
Jun 5, 2012, 5:57:47 AM6/5/12
to googl...@googlegroups.com
Problem solved.  I needed to set both methods to be 'static'. 
Thanks.

 -K
Reply all
Reply to author
Forward
0 new messages