codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Home Page:https://www.codenameone.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CursorIndexOutOfBoundsException while using the gallery on Android

Yberamos opened this issue · comments

Describe the bug
While taking a picture using Capture.capturePhoto(-1, -1); works without issues, choosing one using Display.getInstance().openGallery() throw the exception "CursorIndexOutOfBoundsException ":

Exception: android.database.CursorIndexOutOfBoundsException - Index 0 requested, with a size of 0
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
	at android.database.AbstractCursor.checkPosition(AbstractCursor.java:521)
	at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:139)
	at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:53)
	at android.database.CursorWrapper.getString(CursorWrapper.java:141)
	at com.codename1.impl.android.AndroidImplementation.getImageFilePath(AndroidImplementation.java:7932)
	at com.codename1.impl.android.AndroidImplementation.onActivityResult(AndroidImplementation.java:8041)
	at com.codename1.impl.android.CodenameOneActivity$2.run(CodenameOneActivity.java:352)
	at com.codename1.ui.Display.executeSerialCall(Display.java:1395)
	at com.codename1.ui.Display.processSerialCalls(Display.java:1379)
	at com.codename1.ui.Display.edtLoopImpl(Display.java:1321)
	at com.codename1.ui.Display.invokeAndBlock(Display.java:1503)
	at com.codename1.ui.Display.invokeAndBlock(Display.java:1542)
	at com.codename1.impl.android.AndroidImplementation$3.run(AndroidImplementation.java:1190)
	at com.codename1.ui.Display.executeSerialCall(Display.java:1395)
	at com.codename1.ui.Display.processSerialCalls(Display.java:1379)
	at com.codename1.ui.Display.edtLoopImpl(Display.java:1321)
	at com.codename1.ui.Display.mainEDTLoop(Display.java:1203)
	at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
	at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
	at java.lang.Thread.run(Thread.java:1012)

The strange part is that this issue is only on Android (works fine in the simulator and iOS).

To Reproduce
I've created a fork of KitchenSink (https://github.com/Yberamos/KitchenSinkPicture ). To replicate the bug:

  1. Go in Media
  2. Choose either "Choose image" or "Choose image (scale)"

Expected behavior
A Toast show up with the path of the image

Smartphone (please complete the following information):

  • Device: Samsung Z Fold 4 (Android 13), One + Nord CE2 lite (Android 13) and Redmi 10 (Android 13)