2013-04-07 133 views
0

此代碼崩潰。爲什麼?致命異常asynctask#2 doInBackground

@Override 
    protected String doInBackground(String... params) { 

     try { 
      image_compress = image_compress(changed_image); 

      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        1, 0)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        0, 1)); 


      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        1.2, 1.8)); 

      array_image.add(Effects_change.doGreyscale(image_compress)); 
      array_image.add(Effects_change.doGamma((image_compress), 0.8, 0.8, 
        0.8)); 
      array_image.add(Effects_change.doGamma((image_compress), 1.8, 1.8, 
        1.8)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 1.0, 
        0, 0)); 

      array_image.add(Effects_change.doColorFilter((image_compress), 0.5, 
        0.5, 0.5)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 1.5, 
        1.5, 1.5)); 


      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 1.5, 0.6, 0.12)); 
      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 0.88, 1.45, 1.43)); 

      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 1.2, 0.87, 1.8)); 
      array_image.add(Effects_change.decreaseColorDepth((image_compress), 
        32)); 

      array_image.add(Effects_change.decreaseColorDepth((image_compress), 
        120)); 

      array_image.add(Effects_change.applyReflection(image_compress)); 
      //array_image.add(Effects_change.applynewReflection(image_compress)); 
      array_image.add(Effects_change.applyFleaEffect(image_compress)); 

      array_image.add(Effects_change.sharpen((image_compress), 15)); 



      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 200, 0.50, 0.6, 0.20)); 
      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 150, 1.2, 0.97, 2.1)); 

      array_image.add(Effects_change.applyGaussianBlur(image_compress)); 
      array_image.add(Effects_change.applyBlackFilter(image_compress)); 
      array_image.add(Effects_change.applyMeanRemoval(image_compress)); 

      array_image.add(Effects_change.applySnowEffect(image_compress)); 

      array_image.add(Effects_change.smooth((image_compress), 8)); 
      array_image.add(Effects_change.CharcoalEffect(image_compress)); 

      array_image.add(Effects_change.tintImage((image_compress), 80)); 
      array_image.add(Effects_change.roundCorner((image_compress), 45)); 

      array_image.add(Effects_change.boost((image_compress), 1, 
        (float) 1.5)); 
      array_image.add(Effects_change.boost((image_compress), 2, 
        (float) 0.30)); 
      array_image.add(Effects_change.boost((image_compress), 3, 
        (float) 0.67)); 
      array_image.add(Effects_change.emboss(image_compress)); 

      array_image.add(Effects_change.boost((image_compress), 1, 
        (float) .50)); 

      array_image.add(Effects_change.boost((image_compress), 2, 
        (float) 0.10)); 
      array_image.add(Effects_change.boost((image_compress), 3, 
        (float) 1.5)); 
      array_image.add(Effects_change.engrave(image_compress)); 
      array_image.add(Effects_change.applyHueFilter((image_compress), 3)); 

      array_image.add(Effects_change 
        .changeToNegativeEffect(image_compress)); 
      array_image.add(Effects_change.SketchImage(image_compress)); 

      array_image.add(Effects_change.doColorFilter(image_compress, 1.8, 1.2, 1)); 


      array_image.add(Effects_change.tintImage((image_compress), 180)); 

      array_image.add(Effects_change.applySaturationFilter(image_compress, 2)); 

      array_image.add(Effects_change.createContrast(image_compress, 100)); 

      array_image.add(Effects_change.applySaturationFilter((image_compress), 90)); 
      // array_image.add(Effects_change.posterize(image_compress, 10)); 

      // setProgress(""+(int)((total*100)/lenghtOfFile)); 

     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     //array_image.add(Effects_change.setSepiaColorFilter(image_compress)); 

     return null; 
    } 

    @Override 
    public void onPostExecute(String result) { 
     super.onPostExecute(result); 

     g.setAdapter(new ImageAdapter(Image_add_effects.this)); 
     g.setOnItemSelectedListener(Image_add_effects.this); 

     try { 
      pb.dismiss(); 
      pb=null; 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 
    } 

} 

這是日誌

04-07 22:36:08.450: W/dalvikvm(18429): threadid=13: thread exiting with uncaught exception(group=0x41fe82a0) 
04-07 22:36:08.450: E/AndroidRuntime(18429): FATAL EXCEPTION: AsyncTask #2 
04-07 22:36:08.450: E/AndroidRuntime(18429): java.lang.RuntimeException: An error occured while executing doInBackground() 
04-07 22:36:08.450: E/AndroidRuntime(18429): at android.os.AsyncTask$3.done(AsyncTask.java:299) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.lang.Thread.run(Thread.java:856) 
04-07 22:36:08.450: E/AndroidRuntime(18429): Caused by: java.lang.OutOfMemoryError 

我怎樣才能解決這個問題?

回答

0

原因是java.lang.OutOfMemoryError這意味着您的計算會吃太多的RAM。

然而,不知道你在做什麼,很難說出什麼原因導致了錯誤。可能你創建了太多的圖像/位圖。

這裏是多少RAM,availiable你的應用程序的信息:https://stackoverflow.com/a/9940415/247013

觀念調查:

  • 化妝用的Bitmap.recycle() - 調用它時,你並不需要一個處理位圖
  • 儘量不要將圖像存儲在RAM中,而是將其保存到文件中
  • 看起來您正嘗試預先爲任何可能的效果預先創建圖像 - 考慮重新設計 - 執行一項有效只有當用戶明確要求時(按需)。
+0

謝謝,我找出了由位圖圖像大小引起的問題 – 2013-04-08 16:15:33

相關問題