sandee
sandee

Reputation: 349

What's meaning of this exception?

I am showing image into listview from webservice suppose I am testing application 10 times then 6 time this exception comes please anyone help me. I am calling web service using AsyncTask.

06-12 14:49:53.132: E/dalvikvm-heap(3071): Out of memory on a 1920016-byte allocation.
 06-12 14:49:53.160: E/AndroidRuntime(3071): FATAL EXCEPTION: AsyncTask #3
 06-12 14:49:53.160: E/AndroidRuntime(3071): java.lang.RuntimeException: An error  occured while executing doInBackground()
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at android.os.AsyncTask$3.done(AsyncTask.java:278)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-12 14:49:53.160: E/AndroidRuntime(3071):     at java.lang.Thread.run(Thread.java:856)
06-12 14:49:53.160: E/AndroidRuntime(3071): Caused by: java.lang.OutOfMemoryError
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at an droid.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
06-12 14:49:53.160: E/AndroidRuntime(3071):     at com.rentfaster.utilities.ImageLoader.decodeFile(ImageLoader.java:142)
06-12 14:49:53.160: E/AndroidRuntime(3071):     at com.rentfaster.utilities.ImageLoader.getBitmap(ImageLoader.java:78)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at com.rentfaster.handler.DetailPhotoHandler.imagefecher(DetailPhotoHandler.java:211)
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at com.rentfaster.handler.DetailPhotoHandler.characters(DetailPhotoHandler.java:153)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:163)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
 06-12 14:49:53.160: E/AndroidRuntime(3071):    at com.rentfaster.home.PropertyDetail$Photostask.doInBackground(PropertyDetail.java:1174)
  06-12 14:49:53.160: E/AndroidRuntime(3071):   at com.rentfaster.home.PropertyDetail$Photostask.doInBackground(PropertyDetail.java:1)
06-12 14:49:53.160: E/AndroidRuntime(3071):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-12 14:49:53.160: E/AndroidRuntime(3071):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-12 14:49:53.160: E/AndroidRuntime(3071):     ... 4 more
06-12 14:50:02.882: E/parse exception0(3258):  dont know why
06-12 14:50:02.882: E/XML Error(3258): java.net.MalformedURLException: Protocol not found: &area=53.447557,-113.460058,53.447557,-113.460058&max=100
06-12 14:50:02.921: E/MapActivity(3258): Couldn't get connection factory client

I am still facing Out of memory problem ,I am using this code please help me

//decodes image and scales it to reduce memory consumption
    private static Bitmap decodeFile(File f){
       try {
        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inSampleSize = 2;
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //Find the correct scale value. It should be the power of 2.
        final int REQUIRED_SIZE=70;
        int width_tmp=o.outWidth, height_tmp=o.outHeight;
        int scale=1;
        while(true){
            if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                break;
            width_tmp/=2;
            height_tmp/=2;
            scale*=2;
        }

        //decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();

        o2.inSampleSize=2;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, null);
    } catch (FileNotFoundException e) {}
    return null;
}

Upvotes: 0

Views: 694

Answers (4)

Sachin Gurnani
Sachin Gurnani

Reputation: 2444

You ran out of memory while Creating bitmap coming from ,you need to reduce the size of bitmap using

 BitmapFactory.Options option = new BitmapFactory.Options();
    option.inSampleSize = 2;


Bitmap bm = BitmapFactory.decodeFile(root.getPath() + "/" + imageName,
                            option);
                    imageView.setImageBitmap(bm);

Upvotes: 1

Raghav Sood
Raghav Sood

Reputation: 82533

You are getting a RuntimeException, which has been caused by an OutOfMemoryError. OutOfMemoryErrors usually happen when you try to load an image that is too large for the space allotted by Android to your application.

If you could post the following lines and some of the code above and below them, along with the calling method and explain what you're doing in your app, we can probably help you better:

ImageLoader.java:142
ImageLoader.java:78
DetailPhotoHandler.java:211
DetailPhotoHandler.java:153

Upvotes: 0

Konstantin Pribluda
Konstantin Pribluda

Reputation: 12367

You ran out of memory while decoding bitmap coming from some stream (webservice?) Maybe you should deliver image not as part of message exchange ( where it will be base64 encoded and copied again and again polluting your precious heap ) but as separate request pulling binary stream from server?

Upvotes: 0

Related Questions