4

我正在查询MediaStore.Images.Media.EXTERNAL_CONTENT_URI并且查询工作正常。我能够从具有常数的每一列中获取数据,例如:

currentImage.ImageUrl = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA));
            currentImage.Lat = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.LATITUDE));
            currentImage.Long = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.LONGITUDE));

宽度/高度列没有常数(no MediaStore.Images.Media.WIDTH),所以我尝试使用imagecursor.getLong(imagecursor.getColumnIndex("width"));.

尝试使用 getLong、getString、getInt... 什么都没有 - 总是同样的崩溃。

这是堆栈:

02-22 19:38:26.242: E/AndroidRuntime(1607): FATAL EXCEPTION: main
02-22 19:38:26.242: E/AndroidRuntime(1607): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.MEDIA_SCANNER_FINISHED dat=file:///mnt/sdcard flg=0x10 } in com.Activity.android.chat.service.ChatService$ChatServiceReceiver@415b26c0
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.os.Handler.handleCallback(Handler.java:605)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.os.Looper.loop(Looper.java:137)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at java.lang.reflect.Method.invokeNative(Native Method)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at java.lang.reflect.Method.invoke(Method.java:511)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at dalvik.system.NativeStart.main(Native Method)
02-22 19:38:26.242: E/AndroidRuntime(1607): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.database.CursorWindow.nativeGetLong(Native Method)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.database.CursorWindow.getLong(CursorWindow.java:515)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.database.CursorWindow.getInt(CursorWindow.java:582)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:69)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.database.CursorWrapper.getInt(CursorWrapper.java:102)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at com.Activity.android.chat.service.ChatService.getUserImages(ChatService.java:251)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at com.Activity.android.chat.service.ChatService.access$1(ChatService.java:209)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at com.Activity.android.chat.service.ChatService$ChatServiceReceiver.onReceive(ChatService.java:204)
02-22 19:38:26.242: E/AndroidRuntime(1607):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
02-22 19:38:26.242: E/AndroidRuntime(1607):     ... 9 more

将不胜感激任何帮助...不知道我还能尝试什么。

谢谢!

4

3 回答 3

10

解决方案(愚蠢的错误......):

我没有在投影中包含宽度和高度列......无法理解为什么谷歌不会给它们常量以避免所有这些混淆,但无论如何,解决方案是添加它们。

final String[] columns = {
                MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.TITLE, MediaStore.Images.Media.DATE_TAKEN,
                MediaStore.Images.Media.SIZE, MediaStore.Images.Media.LATITUDE, MediaStore.Images.Media.LONGITUDE, "width", "height"
        };
于 2012-02-23T08:08:00.413 回答
4
        try {
                    Bitmap _bitmapPreScale = BitmapFactory.decodeFile(imagePath);

                    int oldWidth = _bitmapPreScale.getWidth();
                    int oldHeight = _bitmapPreScale.getHeight();
    }catch(Exception e){
         e.printstacktrace();
               }
于 2012-02-22T17:49:43.610 回答
1

似乎您在访问游标数据之前没有调用cursor.moveToFirst() 。

于 2012-02-22T18:23:33.310 回答