0

我使用 ksoap2 从服务器获取数据(我的数据大约 6MB) 我的代码:

                   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            // envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidhttpTranport = new HttpTransportSE(URL,
                    ContantSystem.TimeOut);
            androidhttpTranport.call(SOAP_ACTIONS, envelope);

            Object responseBody = null;
            try {
                responseBody = envelope.getResponse();
            } catch (SoapFault e2) {
                // TODO Auto-generated catch block

            }

当我同步数据时,我的应用程序显示异常:

11-20 17:16:02.271: E/AndroidRuntime(431): FATAL EXCEPTION: Thread-10
11-20 17:16:02.271: E/AndroidRuntime(431): java.lang.OutOfMemoryError
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.push(KXmlParser.java:626)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.pushEntity(KXmlParser.java:794)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.pushText(KXmlParser.java:849)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.nextImpl(KXmlParser.java:354)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.next(KXmlParser.java:1378)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.kxml2.io.KXmlParser.nextText(KXmlParser.java:1432)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.DM.readInstance(DM.java:34)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:462)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:420)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:289)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:422)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:149)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
11-20 17:16:02.271: E/AndroidRuntime(431):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
11-20 17:16:02.271: E/AndroidRuntime(431):  at jp.osaka.APPLIActivity.getMSConditionSupportTime1(APPLIActivity.java:534)
11-20 17:16:02.271: E/AndroidRuntime(431):  at jp.osaka.APPLIActivity.access$2(APPLIActivity.java:517)
11-20 17:16:02.271: E/AndroidRuntime(431):  at jp.osaka.APPLIActivity$myrunable.run(APPLIActivity.java:358)
11-20 17:16:02.271: E/AndroidRuntime(431):  at java.lang.Thread.run(Thread.java:1019)
11-20 17:16:06.960: E/WindowManager(431): Activity jp.osaka.APPLIActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40571980 that was originally added here
11-20 17:16:06.960: E/WindowManager(431): android.view.WindowLeaked: Activity jp.osaka.APPLIActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40571980 that was originally added here
11-20 17:16:06.960: E/WindowManager(431):   at android.view.ViewRoot.<init>(ViewRoot.java:258)
11-20 17:16:06.960: E/WindowManager(431):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
11-20 17:16:06.960: E/WindowManager(431):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-20 17:16:06.960: E/WindowManager(431):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.Dialog.show(Dialog.java:241)
11-20 17:16:06.960: E/WindowManager(431):   at jp.osaka.APPLIActivity.showProccess(APPLIActivity.java:338)
11-20 17:16:06.960: E/WindowManager(431):   at jp.osaka.APPLIActivity.startProgram(APPLIActivity.java:306)
11-20 17:16:06.960: E/WindowManager(431):   at jp.osaka.APPLIActivity.onCreate(APPLIActivity.java:172)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
11-20 17:16:06.960: E/WindowManager(431):   at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 17:16:06.960: E/WindowManager(431):   at android.os.Looper.loop(Looper.java:123)
11-20 17:16:06.960: E/WindowManager(431):   at android.app.ActivityThread.main(ActivityThread.java:3647)
11-20 17:16:06.960: E/WindowManager(431):   at java.lang.reflect.Method.invokeNative(Native Method)
11-20 17:16:06.960: E/WindowManager(431):   at java.lang.reflect.Method.invoke(Method.java:507)
11-20 17:16:06.960: E/WindowManager(431):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-20 17:16:06.960: E/WindowManager(431):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-20 17:16:06.960: E/WindowManager(431):   at dalvik.system.NativeStart.main(Native Method)

设置 android:largeHeap="true"后如果我在 android 4.0.3 上运行我的应用程序,我的应用程序运行正常。但是我在 android 2.3 上运行我的应用程序,我的应用程序死掉并显示异常:java.lang.OutOfMemoryError 为什么?如何解开这个问题?谢谢。

4

2 回答 2

0

这是什么数据?

也许您或库正在读取单个块中的数据,这可能不是一个好主意,请尝试在小缓冲区中读取它,然后将其存储在文件缓存中。

于 2012-11-20T10:47:32.750 回答
0

您可以使用 ActivityManager.getMemoryClass() 和 ActivityManager.getLargeMemoryClass() 来确保分配了更多内存。试试看。

于 2012-11-20T10:47:55.093 回答