2012-12-13 89 views
1

當我運行這段代碼時,我有時會得到錯誤,但不是全部。 我不能看到我的錯誤。致命異常:AsyncTask#1 SkImageDecoder :: Factory返回null

長途區號:

private void processPhotoUpdate(File tempFile) 
     { 
      Log.i(TAG, "Made it into Process Photo Update"); 
      ProcessProfilePhotoTask task = new ProcessProfilePhotoTask() 
       { 
        @Override 
        protected void onPostExecute(Bitmap result) 
         { 
          Log.i(TAG, "Not Null"); 
          if (result != null){      
          Log.i(TAG, "on Post Execute"); 
          android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(result.getWidth(), result.getHeight()); 
          params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL; 
          photo.setLayoutParams(params); 
          photo.setImageBitmap(result); 
          } 
         } 
       };     
        task.execute(tempFile); 
     } 

類我叫的是:

public class ProcessProfilePhotoTask extends AsyncTask<File, ProcessProfilePhotoTask.ProcessingState, Bitmap> { 


public enum ProcessingState { 
    STARTING, 
    PROCESSING_LARGE, 
    FINISHED 
} 


public static final String TAG = "ProcessProfilePhotoTask"; 

public ProcessProfilePhotoTask() { 
    super(); 
} 

@Override 
protected Bitmap doInBackground(File... files) { 
    ProcessingState[] s = new ProcessingState[1]; 
    //BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
    if (files.length != 1) { 
     throw new IllegalArgumentException("We expect to process only one file"); 
    } 
    try { 
     s[0] = ProcessingState.PROCESSING_LARGE; 
     publishProgress(s); 

     Bitmap largePhoto = BitmapFactory.decodeStream(new FileInputStream(files[0])); 
     int height = largePhoto.getHeight(); 
     int width = largePhoto.getWidth(); 
     int density = largePhoto.getDensity(); 
     Log.d(TAG,"large image processing "+ height+"x"+width+"den="+density+"type="); 

     return largePhoto; 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
     return null; 
    } 
} 
} 

的logcat的是。

12-13 15:41:02.064: D/skia(14099): --- SkImageDecoder::Factory returned null 
12-13 15:41:02.064: W/dalvikvm(14099): threadid=9: thread exiting with uncaught    exception (group=0x400259f8) 
12-13 15:41:02.074: E/AndroidRuntime(14099): FATAL EXCEPTION: AsyncTask #1 
12-13 15:41:02.074: E/AndroidRuntime(14099): java.lang.RuntimeException: An error  occured while executing doInBackground() 
12-13 15:41:02.074: E/AndroidRuntime(14099): at android.os.AsyncTask$3.done(AsyncTask.java:200) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at  java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.lang.Thread.run(Thread.java:1102) 
12-13 15:41:02.074: E/AndroidRuntime(14099): Caused by: java.lang.NullPointerException 
12-13 15:41:02.074: E/AndroidRuntime(14099): at com.androidworks.ProcessProfilePhotoTask.doInBackground(ProcessProfilePhotoTask.java:57) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at com.androidworks.ProcessProfilePhotoTask.doInBackground(ProcessProfilePhotoTask.java:1) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at android.os.AsyncTask$2.call(AsyncTask.java:185) 
12-13 15:41:02.074: E/AndroidRuntime(14099): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
12-13 15:41:02.074: E/AndroidRuntime(14099): ... 4 more 
12-13 15:41:04.014: I/Process(14099): Sending signal. PID: 14099 SIG: 9 
+0

你的日誌說'com.androidworks.ProcessProfilePhotoTask.doInBackground(ProcessProfilePhotoTask.java:57)'你能告訴我這是行號57? – MAC

+0

ProcessProfilePhoto中的第57行IS \t int height = largePhoto.getHeight(); – John

+0

你不能調試和檢查什麼是NPE。而且由於你正在檢查結果!= null,你可能不得不選擇整個函數調用來檢查什麼是null。檢查result.getHeight()或result.getWidth()爲空。 – Android

回答

0

通過增加doInBackgroud()這個條件試試這個....

if(null != largePhoto) 
{ 
    // your code here 
} 
else 
{ 
    // error code here 
} 
+0

thanks largePhoto = null; – John

+0

文件\t文件[1](ID = 830102611000)\t \t [0] \t文件(ID = 830102605216)\t \t 路徑\t \t 「/mnt/sdcard/tmp_avatar_1355378309795.jpg」(ID = 830102603648)\t \t \t pathBytes \t(id = 830102606184)\t largePhoto \t null – John

+0

謝謝。你知道爲什麼我有時會得到空,有時我會得到有效的數據。 – John