2011-06-15 81 views
0

我試圖讀取手機中圖像的縮略圖。下面的代碼在Emulator中工作正常,但是在Phone中失敗。它給count = 0(我在電話很多照片):媒體文件閱讀

String[] img = { MediaStore.Images.Thumbnails._ID }; 
cursor imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, img, null,null, MediaStore.Images.Thumbnails.IMAGE_ID + ""); 
int image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); 
count = imagecursor.getCount(); 
System.err.println("image_column_index= " + image_column_index); 
System.err.println("count= " + count); 

您好,感謝您的信息..請在下面找到日誌...其實計數不應該是零的都在這裏。

06-16 15:17:28.360 W/System.err(10250): image_column_index= 0 
    06-16 15:17:28.360 W/System.err(10250): count= 0 
    06-16 15:17:28.370 W/dalvikvm(10250): threadid=1: thread exiting with uncaught exception (group=0x40020ac0) 
    06-16 15:17:28.370 E/AndroidRuntime(10250): FATAL EXCEPTION: main 
    06-16 15:17:28.370 E/AndroidRuntime(10250): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.imagegallery/com.test.imagegallery.LocalThumbnailActivity}: java.lang.ArrayIndexOutOfBoundsException 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.os.Handler.dispatchMessage(Handler.java:99) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.os.Looper.loop(Looper.java:123) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at java.lang.reflect.Method.invokeNative(Native Method) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at java.lang.reflect.Method.invoke(Method.java:521) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at dalvik.system.NativeStart.main(Native Method) 
    06-16 15:17:28.370 E/AndroidRuntime(10250): Caused by: java.lang.ArrayIndexOutOfBoundsException 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at com.test.imagegallery.LocalThumbnailActivity.init_phone_image_grid(LocalThumbnailActivity.java:48) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at com.test.imagegallery.LocalThumbnailActivity.onCreate(LocalThumbnailActivity.java:29) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
    06-16 15:17:28.370 E/AndroidRuntime(10250):  ... 11 more 
    06-16 15:17:28.380 W/ActivityManager(1366): Force finishing activity com.test.imagegallery/.LocalThumbnailActivity 
    06-16 15:17:28.380 W/ActivityManager(1366): Force finishing activity com.test.imagegallery/.ImageGallery 

回答

0
cursor imagecursor = managedQuery(...); 

你的意思是這裏實例化類被稱爲Cursor(這是大寫)。

此外,您應該提供LogCat輸出和您得到的任何異常或錯誤消息。

+0

嗨luckas,在這裏寫下問題時光標是一個錯字。關於日誌貓我看到手機中的錯誤,所以我不能在這裏複製錯誤。它顯示計數= 0,然後ArrayOutOfBoundArray爲活動 – jhon 2011-06-15 17:20:39

+0

因此,你不在虛擬設備上測試?如果是這樣,你應該閱讀[this](http://developer.android.com/guide/developing/device.html)。 – 2011-06-15 17:31:55

+0

嗨,感謝您的信息..請在下面找到下面的日誌...實際上這裏的計數不應該爲零。 E/AndroidRuntime(5413):主要的 E/AndroidRuntime(5413):java.lang.RuntimeException(5413):線程ID = 0 W/dalvikvm(5413):threadid = 1:線程以未捕獲的異常退出(group = 0x40020ac0) :無法啓動活動ComponentInfo {com.ibm.imagegallery/com.ibm.imagegallery.LocalThumbnailActivity}:java.lang.ArrayIndexOutOfBoundsException E/AndroidRuntime(5413):\t at android.app.ActivityThread.performLaunchActivity(ActivityThread.jav ..無法顯示完整日誌 – jhon 2011-06-16 05:57:38