java.lang.OutOfMemoryError - 非常大的SOAP响应

时间:2014-09-09 06:22:06

标签: android xml-parsing out-of-memory ksoap

我有一个Android应用程序,它调用web服务并以xml格式获取新闻!

在解析大量新闻时,它给了我一个outOfMemoryError !!

我该怎么办呢?有什么帮助吗?!

这是我的logcat错误:

09-09 09:17:38.404: E/AndroidRuntime(31578): FATAL EXCEPTION: AsyncTask #4
09-09 09:17:38.404: E/AndroidRuntime(31578): java.lang.RuntimeException: An error occured while executing doInBackground()
09-09 09:17:38.404: E/AndroidRuntime(31578):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.lang.Thread.run(Thread.java:856)
09-09 09:17:38.404: E/AndroidRuntime(31578): Caused by: java.lang.OutOfMemoryError
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.lang.String.<init>(String.java:255)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.lang.String.<init>(String.java:171)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at java.lang.String.<init>(String.java:141)
09-09 09:17:38.404: E/AndroidRuntime(31578):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:190)

我从服务器获取数据的方法

if(categories.equals("") || categories.isEmpty() || categories == null)
            categories = "1;2;3;4;5;6;7;";
            getReportsObjZ.country = "0";
            getReportsObjZ.category = categories;
            getReportsObjZ.fdate = date_from;
            getReportsObjZ.tdate = date_to;

            try 
            {
                SharePoint_GetReportsByCatCntryResponse response = smartSearchSoap.SharePoint_GetReportsByCatCntry(getReportsObjZ);

                reportsXML = smartSearchSoap.getCountriesListFromService();
            }

            catch (Exception e) 
            {
                e.printStackTrace();
            }

            XMLParser parser = new XMLParser();

            Document doc = parser.getDomElement(reportsXML);

            NodeList nl = doc.getElementsByTagName(TAG_LIST);

            dbObject.open();


            dbObject.delete_ALL_ROWS();

            for (int i = 0; i < nl.getLength(); i++) 
            {
                Element e = (Element) nl.item(i);

                String just_date_without_time = getJustDATE(parser.getValue(e,TAG_CREATED_P));
                String just_time_without_date = getJustTIME(parser.getValue(e,TAG_CREATED_P));
                String numberical_category = "";



                dbObject.createEntry(parser.getValue(e, TAG_TITLE),
                        parser.getValue(e, TAG_COUNTRY_ID),
                        parser.getValue(e, TAG_DESCRIPTION),
                        parser.getValue(e, TAG_IDP),
                        removeSpecialChars(parser.getValue(e, TAG_CATEGORYP)),
                        just_date_without_time, just_time_without_date,
                        parser.getValue(e, TAG_CREATED_BY),
                        parser.getValue(e, TAG_TAGS),
                        parser.getValue(e, TAG_READ_BY),
                        removeSpecialChars(parser.getValue(e, TAG_CITY)),
                        (parser.getValue(e, TAG_DIR)),
                        removeSpecialChars(parser.getValue(e, TAG_LINK)),numberical_category);
            }

            dbObject.close();

1 个答案:

答案 0 :(得分:1)

android有堆限制,从文件中读取XML数据并方便地解析

OR

尝试将android:largeHeap="true"放在清单文件的应用程序标记中。