为什么用android 2.3显示错误OutOfMemoryError

时间:2012-11-20 10:40:19

标签: android json ksoap2

我使用kso​​ap2从服务器获取数据(我的数据约为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)

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

2 个答案:

答案 0 :(得分:0)

这是什么类型的数据?

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

答案 1 :(得分:0)

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