I'm querying MediaStore.Images.Media.EXTERNAL_CONTENT_URI
and the query works fine. I'm able to get the data from every column that has a constant, for example:
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));
The width/height columns has no constant (no MediaStore.Images.Media.WIDTH
) so I'm trying to access them with imagecursor.getLong(imagecursor.getColumnIndex("width"));
.
Tried to use getLong, getString, getInt... nothing - always the same crash.
Here's the stack:
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
Would appreciate any help with this... have no idea what else can I try.
Thank you!
Solution (stupid mistake...):
I didn't include the width and height columns in the projection... Can't understand why Google won't give them constants to avoid all this confusion but anyways, the solution was to add them.
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"
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With