Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:52:00+00:00 2026-06-17T14:52:00+00:00

I am using the below code to fetch xml file from the server and

  • 0

I am using the below code to fetch xml file from the server and due to heavy and large xml file, it got crashed and showing Out of memory Issue.

 public class Connect {

   static BufferedReader in=null;
   String result=null;
   Context context;
   //Establish connection with web server
      public String HTTPConnect(String uri1,List<NameValuePair> list,Context context)
      {

    this.context=context;
    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(uri1);

        if(list!=null)
        {
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list);

        httpPost.setEntity(formEntity);
        }

        HttpResponse httpResponse = httpClient.execute(httpPost);
       in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");

        long heapSize = Runtime.getRuntime().totalMemory();

        if(in!=null)
        {
            while ((line = in.readLine()) != null) {//crasheg here
              sb.append(line + NL);
            }
            in.close();
        }

        result = sb.toString();


}
    catch(UnsupportedEncodingException e)
    {
        String err = (e.getMessage()==null)?"Cant connect to server":e.getMessage();

        ShowDialog();
    }
    catch (MalformedURLException e) {
        String err = (e.getMessage()==null)?"Malformed Exception":e.getMessage();

        ShowDialog();
     } 
     catch(Exception ex)
     {

         String err = (ex.getMessage()==null)?"NetworkConnectionException":ex.getMessage();

         ShowDialog();
     }
    finally {
        if (in != null) {
            try {
                    in.close();
             } catch (Exception ex) {
                 String err = (ex.getMessage()==null)?"Excepion":ex.getMessage();

                 ex.printStackTrace();

            }
        }

     }

    return result;

   }

I know that that I am copying the whole XML in String and due to heavy file, It gor crashing. It is working fine in small size of XML file, but what are the alternative for large xml file. I am uing SAX parser for parsing this xml file.

[EDIT]
Below is the logcat:

 FATAL EXCEPTION: AsyncTask #4
 java.lang.RuntimeException: An error occured while executing doInBackground()
 at android.os.AsyncTask$3.done(AsyncTask.java:200)
 at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
 at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
 at java.util.concurrent.FutureTask.run(FutureTask.java:137)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
 at java.lang.Thread.run(Thread.java:1096)
 Caused by: java.lang.OutOfMemoryError
 java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
 java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:136)
 java.lang.StringBuilder.append(StringBuilder.java:272)
 java.io.BufferedReader.readLine(BufferedReader.java:452)
 com.kxs.appitize.Connect.HTTPConnect(Connect.java:56)
 com.kxs.appitize.ListRestaurants$Asyn_rest.doInBackground(ListRestaurants.java:168)
 com.kxs.appitize.ListRestaurants$Asyn_rest.doInBackground(ListRestaurants.java:1)
 01-at android.os.AsyncTask$2.call(AsyncTask.java:185)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  Activity com.kxs.appitize.TabsMainActivity has leaked window    com.android.internal.policy.impl.PhoneWindow$DecorView@44f4fb28 that was originally added here
 android.view.WindowLeaked: Activity com.kxs.appitize.TabsMainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f4fb28 that was originally added here
 at android.view.ViewRoot.<init>(ViewRoot.java:247)
 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
 at android.view.Window$LocalWindowManager.addView(Window.java:424)
 at android.app.Dialog.show(Dialog.java:241)
 at com.kxs.appitize.ListRestaurants$Asyn_rest.onPreExecute(ListRestaurants.java:156)
 at android.os.AsyncTask.execute(AsyncTask.java:391)
 at com.kxs.appitize.ListRestaurants.onCreate(ListRestaurants.java:133)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
 at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
 at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
 at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at com.kxs.appitize.TabGroupActivity.startChildActivity(TabGroupActivity.java:72)
  at com.kxs.appitize.ListCategories$1.onClick(ListCategories.java:109)
 at android.view.View.performClick(View.java:2408)
 at android.view.View$PerformClick.run(View.java:8816)
 at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
 at android.os.Looper.loop(Looper.java:123)     
 at android.app.ActivityThread.main(ActivityThread.java:4627)
 at java.lang.reflect.Method.invokeNative(Native Method)
 java.lang.reflect.Method.invoke(Method.java:521)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:52:01+00:00Added an answer on June 17, 2026 at 2:52 pm

    copying the whole XML in String and due to heavy file

    Bad idea. First you need to cache the xml in a temporary directory. It should never be in the RAM.

    Once you do that use SAX to parse the file. During parsing try not to keep the whole structure in the RAM, instead parse in bite sized chunks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the below code to fetch events from google calendar. But I
I tried created an XML file using below code. $xml = new SimpleXMLElement('<xml />');
I am using below code to generate photo gallery from a folder. How can
Hi i am using below code to display city value from database -- <?php
I am using the below code to scrape over XFN content from web page
I am using an XMLHttpRequest to fetch an image from a server (run locally
I am using the code below to print from an array but its printing
HI i have a peice of code which takes information from a xml file
Using the below code, my template loads fine until I submit the from, then
I am using the code below to get information from a database and make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.