2014-10-09 158 views
0

未知的URL文件獲取上述錯誤java.lang.IllegalArgumentException異常:在android.content.ContentResolver.delete

builder.setOnCancelListener(new DialogInterface.OnCancelListener() { 
        @Override 
        public void onCancel(DialogInterface dialog) { 

         if (mImageCaptureUri != null) 
         { 
          //exception at below line 
          getContentResolver().delete(mImageCaptureUri, null,null); 
          mImageCaptureUri = null; 
         } 
        } 
       }); 

我嘗試檢查,如果文件被new File(mImageCaptureUri.getPath()).exists()它的存在,但我依然得到了異常,因爲存在

java.lang.IllegalArgumentException: Unknown URL file:///storage/sdcard0/tmp_avatar_1412858553212.jpg  
at android.content.ContentResolver.delete(ContentResolver.java:984) 
+0

看起來不像一個有效的(即系統定義的)內容URI。你想達到什麼目的? – Trinimon 2014-10-09 12:48:39

回答

1

我想檢查是否文件被新的文件存在(mImageCaptureUri.getPath())。存在()存在

請注意,there is no requirement that a Uri point to a file that you can access

還是我得到的異常,因爲

java.lang.IllegalArgumentException: Unknown URL file:///storage/sdcard0/tmp_avatar_1412858553212.jpg at android.content.ContentResolver.delete(ContentResolver.java:984) 

ContentResolver主要是爲content://方案。對於file://方案,您可能需要嘗試直接刪除文件。

相關問題