这个例外是什么意思?

时间:2012-06-12 09:27:51

标签: android

我在webservice中将图像显示到listview中,假设我正在测试应用程序10次    然后6次这个例外来了请任何人帮助我。                                                           我使用AsyncTask调用Web服务。

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

我仍然面临内存不足问题,我正在使用此代码请帮帮我

//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;
}

4 个答案:

答案 0 :(得分:1)

在创建位图时,内存不足,需要使用

来减小位图的大小
 BitmapFactory.Options option = new BitmapFactory.Options();
    option.inSampleSize = 2;


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

答案 1 :(得分:0)

解码来自某些流的位图(webservice?)时内存不足 也许你应该提供图像而不是作为消息交换的一部分(它将在哪里 base64编码和复制一次又一次地污染你的珍贵堆)但作为单独的请求从服务器拉二进制流?

答案 2 :(得分:0)

您收到的RuntimeException是由OutOfMemoryError引起的。当您尝试将对于Android分配的空间而言太大的图像加载到您的应用程序时,通常会发生OutOfMemoryErrors。

如果您可以发布以下行以及它们上方和下方的一些代码,以及调用方法并解释您在应用中正在执行的操作,我们可能会帮助您更好:

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

答案 3 :(得分:0)