gpt4 book ai didi

Android 应用程序中的 java.lang.OutOfMemoryError

转载 作者:行者123 更新时间:2023-12-01 22:44:21 25 4
gpt4 key购买 nike

        try {       
Gson gson = new Gson();
try
{
((ProfileActivity)getActivity()).interactionResult = gson.fromJson(HomeCardString.toString(), InteractionSummaryResult.class);

}
catch(Exception e)
{
Log.i("myyyy", e.getMessage());
e.printStackTrace();
}

} catch (Throwable t) {
Log.e("My App", "Could not parse malformed JSON: \"" + responseString + "\"" + t.getMessage());
}

gson.fromgson..... 此行在 Throwable t .... 处创建异常。我在 HomeCardString.toString() 中的数据非常大。记事本文件大约 1.9MB。我无法减少该数据的大小。该怎么办?

08-29 16:34:36.963: E/AndroidRuntime(29319): FATAL EXCEPTION: main
08-29 16:34:36.963: E/AndroidRuntime(29319): java.lang.OutOfMemoryError
08-29 16:34:36.963: E/AndroidRuntime(29319): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
08-29 16:34:36.963: E/AndroidRuntime(29319): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
08-29 16:34:36.963: E/AndroidRuntime(29319): at java.lang.StringBuilder.append(StringBuilder.java:216)
08-29 16:34:36.963: E/AndroidRuntime(29319): at com.stalker.androidapp.InteractionTabFragment$ProfileInteractionCall.onPostExecute(InteractionTabFragment.java:175)
08-29 16:34:36.963: E/AndroidRuntime(29319): at com.stalker.androidapp.InteractionTabFragment$ProfileInteractionCall.onPostExecute(InteractionTabFragment.java:1)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.os.AsyncTask.finish(AsyncTask.java:602)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.os.AsyncTask.access$600(AsyncTask.java:156)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.os.Looper.loop(Looper.java:137)
08-29 16:34:36.963: E/AndroidRuntime(29319): at android.app.ActivityThread.main(ActivityThread.java:4448)
08-29 16:34:36.963: E/AndroidRuntime(29319): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 16:34:36.963: E/AndroidRuntime(29319): at java.lang.reflect.Method.invoke(Method.java:511)
08-29 16:34:36.963: E/AndroidRuntime(29319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
08-29 16:34:36.963: E/AndroidRuntime(29319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
08-29 16:34:36.963: E/AndroidRuntime(29319): at dalvik.system.NativeStart.main(Native Method)

最佳答案

您可以尝试在 list 中为您的应用程序设置android:largeHeap="true"。引用如下:

http://developer.android.com/reference/android/R.styleable.html#AndroidManifestApplication_largeHeap

如果这不起作用,请查看这篇文章:

JAVA - Best approach to parse huge (extra large) JSON file

关于Android 应用程序中的 java.lang.OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567535/

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