开发者

Gson from JSon OutOfMemmoryError

开发者 https://www.devze.com 2023-01-18 09:25 出处:网络
I have a web service that returns a image in Base64 format. The body response, as Fiddler says has a Content-Length: 383143.

I have a web service that returns a image in Base64 format. The body response, as Fiddler says has a Content-Length: 383143.

The response is like: {... two strings... and... ImageBase64":"iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAAAXNSR0IArs4c.....}

I request data from the web service and I receive it in a string format. When I try the following:

LargeImage trackLargeImage = new Gson().fromJson(webServiceStringResponse, LargeImage.class);

It takes a while and I get this error:

n.JsonParser.parse(JsonParser.java:54)

n.JsonParser.parse(JsonParser.java:54)> 09-28 13:21:08.844:
> ERROR/AndroidRuntime(217): Uncaught
> handler: thread main exiting due to
> uncaught exception 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):
> java.lang.RuntimeException: Unable to
> start activity
> ComponentInfo{com.vorienteering.virtualorienteering/com.vorienteering.virtualorienteering.TrackDetailsActivity}:
> com.google.gson.JsonParseException:
> Failed parsing JSON source:
> java.io.StringReader@437ddd18 to Json
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread.access$2100(ActivityThread.java:116)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.os.Looper.loop(Looper.java:123)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread.main(ActivityThread.java:4203)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> java.lang.reflect.Method.invokeNative(Native
> Method) 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> java.lang.reflect.Method.invoke(Method.java:521)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.开发者_StackOverflow中文版java:549)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> dalvik.system.NativeStart.main(Native
> Method) 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217): Caused by:
> com.google.gson.JsonParseException:
> Failed parsing JSON source:
> java.io.StringReader@437ddd18 to Json
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParser.parse(JsonParser.java:63)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.Gson.fromJson(Gson.java:443)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.Gson.fromJson(Gson.java:396)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.Gson.fromJson(Gson.java:372)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.vorienteering.virtualorienteering.TrackDetailsActivity.getData(TrackDetailsActivity.java:51)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.vorienteering.virtualorienteering.TrackDetailsActivity.onCreate(TrackDetailsActivity.java:37)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     ... 11
> more 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217): Caused by:
> java.lang.OutOfMemoryError 09-28
> 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.SimpleCharStream.ExpandBuff(SimpleCharStream.java:43)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.SimpleCharStream.FillBuff(SimpleCharStream.java:102)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.SimpleCharStream.readChar(SimpleCharStream.java:196)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavaccTokenManager.jjMoveNfa_0(JsonParserJavaccTokenManager.java:769)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavaccTokenManager.jjStartNfaWithStates_0(JsonParserJavaccTokenManager.java:379)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavaccTokenManager.jjMoveStringLiteralDfa0_0(JsonParserJavaccTokenManager.java:194)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavaccTokenManager.getNextToken(JsonParserJavaccTokenManager.java:1104)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavacc.jj_ntk(JsonParserJavacc.java:635)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavacc.JsonValue(JsonParserJavacc.java:204)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavacc.Pair(JsonParserJavacc.java:112)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavacc.JsonObject(JsonParserJavacc.java:88)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParserJavacc.parse(JsonParserJavacc.java:36)
> 09-28 13:21:08.874:
> ERROR/AndroidRuntime(217):     at
> com.google.gson.JsonParser.parse(JsonParser.java:54)n.JsonParser.parse(JsonParser.java:54)

n.JsonParser.parse(JsonParser.java:54)

If the image is a not complex, then it works fine, if the image is complex the out of memory error occurs. Any ideas ? Thank you for your time.

0

精彩评论

暂无评论...
验证码 换一张
取 消