媒体文件阅读

时间:2011-06-15 15:42:49

标签: android media

我试图读取手机中图像的缩略图。下面的代码在模拟器中工作正常但在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

1 个答案:

答案 0 :(得分:0)

cursor imagecursor = managedQuery(...);

您在此处实例化的类称为Cursor(它是大写的)。

此外,您应该提供LogCat输出以及您获得的任何异常或错误消息。