Я не могу правильно запустить эту функцию
private fun getImageOrientation(): Int {
val imageColumns = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION)
val imageOrderBy = MediaStore.Images.Media._ID + " DESC"
val cursor: Cursor? = contentResolver.query(photoURI!!, imageColumns, null, null, null)
if (cursor!!.moveToFirst()) {
val orientation: Int = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION))
cursor.close()
return orientation
} else {
return 0
}
}
photoURI
- это переменная, содержащая URI изображения, снятого с камеры. Приложение вызывает эту ошибку
E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.polito.phony.lab1, PID: 3886
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { }} to activity {it.polito.phony.lab1/it.polito.phony.lab1.EditProfileActivity}: android.database.CursorIndexOutOfBoundsException: Requested column: -1, # of columns: 0
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.database.CursorIndexOutOfBoundsException: Requested column: -1, # of columns: 0
at android.database.MatrixCursor.get(MatrixCursor.java:66)
at android.database.MatrixCursor.getInt(MatrixCursor.java:269)
at android.database.CursorWrapper.getInt(CursorWrapper.java:122)
at it.polito.phony.lab1.EditProfileActivity.getImageOrientation(EditProfileActivity.kt:193)
at it.polito.phony.lab1.EditProfileActivity.onActivityResult(EditProfileActivity.kt:171)
at android.app.Activity.dispatchActivityResult(Activity.java:6915)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
в строке
val orientation: Int = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION))