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 8251583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:17:07+00:00 2026-06-08T00:17:07+00:00

The class below parses an rss feed and draws images/text on the screen using

  • 0

The class below parses an rss feed and draws images/text on the screen using AsyncTask. I was using a nasa rss feed. Last night I switched to the same feed but with a larger image. Now when I try to press the refresh button it runs out of memory. How can I handle this? I know it’s just because the image is so large (roughly 6mb, compared to 36kb of the other image) and I’ve read that it being static doesn’t help either. I don’t see any way around it being static though as I need to retrieve final_image as a separate instance of the class for when you set the wallpaper as the image. So everything below works with a smaller image. With a large image, it works once but if you try to push the refresh button (which just runs RssParseSync.execute()) it fails to refresh and I get the error below. I want the larger image because the small image looked really bad when setting it as the wallpaper.

public class RssParseSync extends AsyncTask<String,String,Bitmap>{  

        private Activity parent;
        private ProgressDialog dialog;
        private static Bitmap final_image; //must be static because a new instance is required to access getFinalImage();


        public RssParseSync(Activity parent){this.parent =parent;}//constructor to pass parent activity, need this to call findViewById

                private XmlPullParser makeParser(){

                }

                @Override
                protected Bitmap doInBackground(String... info){

                    URL iotd;
                    int count=info.length;
                    String title="",link="",description="",date="";

                    System.out.println("Number of params is "+count);

                    try{

                        iotd = new URL("http://www.nasa.gov/rss/lg_image_of_the_day.rss");//set URl
                        BufferedReader in;//new BufferedReader
                        in = new BufferedReader(new InputStreamReader(iotd.openStream()));//get rss

                        XmlPullParserFactory factory;
                        factory = XmlPullParserFactory.newInstance();//new factory


                        factory.setNamespaceAware(true);
                        XmlPullParser xpp;
                        xpp = factory.newPullParser();
                        xpp.setInput(in);

                        //rss is now parsed, free to use XmlPullParser functions to move around and evaulate the rss

                        int eventType;
                        eventType = xpp.getEventType();//returns an int which mean different things (START_DOCUMENT,START_TAG,etc)


                    while(eventType!=XmlPullParser.END_DOCUMENT){//while the document has words

                     switch(eventType){

                        case XmlPullParser.START_DOCUMENT://beginning of xml
                            break;
                        case XmlPullParser.START_TAG://case : at beginning of new tag
                            String tagName=xpp.getName();
                            System.out.println(tagName+" "+xpp.getDepth());

                            if(tagName.equals("title")&& xpp.getDepth()==4){//depth is specific to this certain rss feed, there are multiple tags with the same names
                                info[0]=xpp.nextText();
                                title=info[0];

                            }

                            if(tagName.equals("description")&& xpp.getDepth()==4){//depth is specific to this certain rss feed, there are multiple tags with the same names
                                info[1]=xpp.nextText();
                                description=info[1];    
                                StringBuilder tabbed=new StringBuilder(description);
                                tabbed.insert(0, "\t");
                                description=tabbed.toString();
                                //info[1]=description;
                            }

                            if(tagName.equals("pubDate")){//no depth needed, only one tag is named pubDate
                                info[2]=xpp.nextText();
                                date=info[2];                           
                            }

                            if(tagName.equals("enclosure")&&xpp.getDepth()==4){//this is where our image url is. this url is an attribute of the "enclosure" tag
                                //System.out.println("Enclosure has "+xpp.getAttributeCount());
                                for(int i=0; i<=xpp.getAttributeCount()-1; i++){
                                    System.out.println("in for");
                                    if(xpp.getAttributeName(i).equals("url")){
                                        link=xpp.getAttributeValue(i);
                                        info[3]=link;
                                        //System.out.println(link);
                                    }
                                }
                            }
                            break;

                        }
                        eventType=xpp.next();
                    }//switch

                        publishProgress(title,description,date,link);

                        in.close();//close BufferedReader
                    } catch (MalformedURLException e){
                        e.printStackTrace();
                    }catch(XmlPullParserException e1){
                        e1.printStackTrace();
                    }catch(IOException e2){
                        e2.printStackTrace();
                    }         
                    Bitmap image=getBitmapFromURL(info[3]);

                    return image;
                }
                @Override
                protected void onProgressUpdate(String... progress){
                    try {
                        System.out.println("onProgressUpdate");
                        resetDisplay(progress[0],progress[1],progress[2],progress[3]);//feeding parsed rss values, title, description, date, and link
                    } catch (MalformedURLException e) {//both exceptions are thrown by resetDisplay
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

                protected void onPostExecute(Bitmap image){//error when doing this in resetDisplay.... onPostExecute is invoked by the ui thread so this may be why it works here and not in resetDisplay
                    ImageView imageView=(ImageView) parent.findViewById(R.id.imageDisplay);
                    imageView.setImageBitmap(image);
                    final_image=image;
                    dialog.dismiss();

                }

                protected void onPreExecute(){
                     dialog=ProgressDialog.show(parent, "Loading", "Loading the image of the day");
                }

                private void resetDisplay(String title, String description,String date, String link) throws MalformedURLException, IOException{

                    TextView titleView=(TextView) parent.findViewById(R.id.imageTitle);
                    titleView.setText(title);

                    TextView dateView=(TextView) parent.findViewById(R.id.imageDate);
                    dateView.setText(date);

                    TextView descriptionView=(TextView) parent.findViewById(R.id.imageDescription);
                    descriptionView.setText(description);

                }

                public Bitmap getBitmapFromURL(String url) {
                    try {
                    Bitmap bitmap=null; 
                    InputStream input = new java.net.URL(url).openStream();
                    bitmap = BitmapFactory.decodeStream(input);//Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null.
                    input.close();
                    return bitmap;
                    } catch (IOException ioe) { return null; }

                }

                public Bitmap getFinalImage(){
                    return final_image;
                };


    }//class

Refresh method

public void onRefresh(){
    System.out.println("in onRefresh");
    new RssParseSync(getActivity()).execute(title,description,date,link);
}

Logcat log

07-20 17:44:18.470: I/System.out(7581): onProgressUpdate
07-20 17:44:18.770: D/dalvikvm(7581): GC_FOR_ALLOC freed 190K, 3% free 26538K/27299K, paused 46ms
07-20 17:44:18.770: I/dalvikvm-heap(7581): Forcing collection of SoftReferences for 24107536-byte allocation
07-20 17:44:18.790: D/dalvikvm(7581): GC_BEFORE_OOM freed 18K, 3% free 26519K/27299K, paused 23ms
07-20 17:44:18.790: E/dalvikvm-heap(7581): Out of memory on a 24107536-byte allocation.
07-20 17:44:18.790: I/dalvikvm(7581): "AsyncTask #2" prio=5 tid=13 RUNNABLE
07-20 17:44:18.790: I/dalvikvm(7581):   | group="main" sCount=0 dsCount=0 obj=0x40d6cac8 self=0x2412840
07-20 17:44:18.790: I/dalvikvm(7581):   | sysTid=7646 nice=10 sched=0/0 cgrp=default handle=32889544
07-20 17:44:18.790: I/dalvikvm(7581):   | schedstat=( 0 0 0 ) utm=7 stm=0 core=1
07-20 17:44:18.790: I/dalvikvm(7581):   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
07-20 17:44:18.800: I/dalvikvm(7581):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:719)
07-20 17:44:18.800: I/dalvikvm(7581):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:791)
07-20 17:44:18.800: I/dalvikvm(7581):   at com.wajumbie.nasadailyimage.RssParseSync.getBitmapFromURL(RssParseSync.java:162)
07-20 17:44:18.800: I/dalvikvm(7581):   at com.wajumbie.nasadailyimage.RssParseSync.doInBackground(RssParseSync.java:116)
07-20 17:44:18.800: I/dalvikvm(7581):   at com.wajumbie.nasadailyimage.RssParseSync.doInBackground(RssParseSync.java:1)
07-20 17:44:18.800: I/dalvikvm(7581):   at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-20 17:44:18.800: I/dalvikvm(7581):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-20 17:44:18.800: I/dalvikvm(7581):   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-20 17:44:18.800: I/dalvikvm(7581):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
07-20 17:44:18.800: I/dalvikvm(7581):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-20 17:44:18.800: I/dalvikvm(7581):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-20 17:44:18.800: I/dalvikvm(7581):   at java.lang.Thread.run(Thread.java:864)
07-20 17:44:18.800: E/dalvikvm(7581): Out of memory: Heap Size=34019KB, Allocated=26519KB, Limit=49152KB
07-20 17:44:18.800: E/dalvikvm(7581): Extra info: Footprint=27299KB, Allowed Footprint=34019KB, Trimmed=1212KB
07-20 17:44:18.800: D/skia(7581): --- decoder->decode returned false
07-20 17:44:18.800: W/dalvikvm(7581): threadid=13: thread exiting with uncaught exception (group=0x40aa3a08)
07-20 17:44:18.810: E/AndroidRuntime(7581): FATAL EXCEPTION: AsyncTask #2
07-20 17:44:18.810: E/AndroidRuntime(7581): java.lang.RuntimeException: An error occured while executing doInBackground()
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.lang.Thread.run(Thread.java:864)
07-20 17:44:18.810: E/AndroidRuntime(7581): Caused by: java.lang.OutOfMemoryError: (Heap Size=34019KB, Allocated=26519KB)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:719)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:791)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at com.wajumbie.nasadailyimage.RssParseSync.getBitmapFromURL(RssParseSync.java:162)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at com.wajumbie.nasadailyimage.RssParseSync.doInBackground(RssParseSync.java:116)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at com.wajumbie.nasadailyimage.RssParseSync.doInBackground(RssParseSync.java:1)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-20 17:44:18.810: E/AndroidRuntime(7581):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-20 17:44:18.810: E/AndroidRuntime(7581):     ... 5 more
07-20 17:44:19.061: D/OpenGLRenderer(7581): Flushing caches (mode 0)
07-20 17:44:19.061: D/memalloc(7581): ion: Unmapping buffer  base:0x52738000 size:2088960
07-20 17:44:19.061: D/memalloc(7581): ion: Unmapping buffer  base:0x52f7c000 size:2088960
07-20 17:44:19.061: D/memalloc(7581): ion: Unmapping buffer  base:0x53477000 size:2088960
07-20 17:44:19.081: D/OpenGLRenderer(7581): Flushing caches (mode 0)
07-20 17:44:19.111: D/memalloc(7581): ion: Unmapping buffer  base:0x52bea000 size:524288
07-20 17:44:19.121: D/memalloc(7581): ion: Unmapping buffer  base:0x5367d000 size:524288
07-20 17:44:19.121: D/memalloc(7581): ion: Unmapping buffer  base:0x53326000 size:524288
07-20 17:44:19.141: D/OpenGLRenderer(7581): Flushing caches (mode 2)
07-20 17:44:19.181: E/WindowManager(7581): Activity com.wajumbie.nasadailyimage.NasaAppActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40d92b30 that was originally added here
07-20 17:44:19.181: E/WindowManager(7581): android.view.WindowLeaked: Activity com.wajumbie.nasadailyimage.NasaAppActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40d92b30 that was originally added here
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:380)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:372)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.Window$LocalWindowManager.addView(Window.java:557)
07-20 17:44:19.181: E/WindowManager(7581):  at android.app.Dialog.show(Dialog.java:301)
07-20 17:44:19.181: E/WindowManager(7581):  at android.app.ProgressDialog.show(ProgressDialog.java:116)
07-20 17:44:19.181: E/WindowManager(7581):  at android.app.ProgressDialog.show(ProgressDialog.java:99)
07-20 17:44:19.181: E/WindowManager(7581):  at android.app.ProgressDialog.show(ProgressDialog.java:94)
07-20 17:44:19.181: E/WindowManager(7581):  at com.wajumbie.nasadailyimage.RssParseSync.onPreExecute(RssParseSync.java:142)
07-20 17:44:19.181: E/WindowManager(7581):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
07-20 17:44:19.181: E/WindowManager(7581):  at android.os.AsyncTask.execute(AsyncTask.java:511)
07-20 17:44:19.181: E/WindowManager(7581):  at com.wajumbie.nasadailyimage.NasaDailyImage.onRefresh(NasaDailyImage.java:57)
07-20 17:44:19.181: E/WindowManager(7581):  at com.wajumbie.nasadailyimage.NasaAppActivity$1.run(NasaAppActivity.java:48)
07-20 17:44:19.181: E/WindowManager(7581):  at com.wajumbie.nasadailyimage.NasaAppActivity.onRefreshClicked(NasaAppActivity.java:51)
07-20 17:44:19.181: E/WindowManager(7581):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 17:44:19.181: E/WindowManager(7581):  at java.lang.reflect.Method.invoke(Method.java:511)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.View$1.onClick(View.java:3066)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.View.performClick(View.java:3538)
07-20 17:44:19.181: E/WindowManager(7581):  at android.view.View$PerformClick.run(View.java:14330)
07-20 17:44:19.181: E/WindowManager(7581):  at android.os.Handler.handleCallback(Handler.java:607)
07-20 17:44:19.181: E/WindowManager(7581):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-20 17:44:19.181: E/WindowManager(7581):  at android.os.Looper.loop(Looper.java:156)
07-20 17:44:19.181: E/WindowManager(7581):  at android.app.ActivityThread.main(ActivityThread.java:5008)
07-20 17:44:19.181: E/WindowManager(7581):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 17:44:19.181: E/WindowManager(7581):  at java.lang.reflect.Method.invoke(Method.java:511)
07-20 17:44:19.181: E/WindowManager(7581):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-20 17:44:19.181: E/WindowManager(7581):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-20 17:44:19.181: E/WindowManager(7581):  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-08T00:17:10+00:00Added an answer on June 8, 2026 at 12:17 am

    You need to resize the image if it is very large.

    Do as follows:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(new URL(imageUrl).openStream(),null,options);
    //use your required height and width in place of 80 (size of imageview maybe)
    options.inSampleSize = calculateInSampleSize(options,80, 80); 
    options.inJustDecodeBounds = false;
    Bitmap bmp = BitmapFactory.decodeStream(new URL(imageUrl).openStream(),null,options);
    
    
    public int calculateInSampleSize(BitmapFactory.Options options,
            int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;
    
        if (height > reqHeight || width > reqWidth) {
            if (width > height) {
                inSampleSize = Math.round((float) height / (float) reqHeight);
            } else {
                inSampleSize = Math.round((float) width / (float) reqWidth);
            }
        }
        return inSampleSize;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the class below, I am using a singleThreadScheduledExecutor. My question is, do I
I tried to send an email using this class below, but no success, no
I am using Java to read an RSS feed from a URL, parse the
We had a view (.cshtml) which rendered XML for an RSS feed using ASP.NET
The class below is my delete class, i want to delete the users from
In the class below, only the second constructor takes a ForumThread object. Otherwise, it
I have posted my class below and with sample data. I need to pass
Can any one volunteer why the class below fails? ... src/model/user.rb:18: undefined method `set_schema'
as you can see the class below declares 2 private instance variables and 2
I want to add a new property bool IsValid to my class below. I

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.