From c524044d11398d770c85a194682f5f32e40893a9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 14 Nov 2016 18:22:42 +0100 Subject: [PATCH] crashfix at getRealPathFromURI --- .../com/simplemobiletools/gallery/extensions/context.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 2e273b348..161a3a38f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -10,9 +10,11 @@ fun Context.getRealPathFromURI(uri: Uri): String? { try { val projection = arrayOf(MediaStore.Images.Media.DATA) cursor = contentResolver.query(uri, projection, null, null, null) - val index = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) - cursor.moveToFirst() - return cursor.getString(index) + if (cursor != null && cursor.moveToFirst()) { + val index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) + return cursor.getString(index) + } + return null } finally { cursor?.close() }