如何解决媒体文件读取
| 我正在尝试读取手机中图像的缩略图。下面的代码在Emulator中工作正常,但在Phone中失败。 gives0ѭ(我的手机中有很多照片):String[] img = { MediaStore.Images.Thumbnails._ID };
cursor imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,img,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
解决方法
cursor imagecursor = managedQuery(...);
您要在此处实例化的类称为Cursor
(大写)。
另外,您还应该提供LogCat输出以及所获得的任何异常或错误消息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。