changeset 2643:28ca1e59e76f

Android: Catch NotFoundException when loading resource... This allows HandyFTP to start up on Android now, with missing resources. APIs should return null on failure not throw an exception.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 13 Aug 2021 22:19:45 +0000
parents 3edc64443b71
children 45a6b33a003a
files android/DWindows.kt
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Fri Aug 13 21:50:47 2021 +0000
+++ b/android/DWindows.kt	Fri Aug 13 22:19:45 2021 +0000
@@ -9,6 +9,7 @@
 import android.content.*
 import android.content.pm.ActivityInfo
 import android.content.res.Configuration
+import android.content.res.Resources
 import android.database.Cursor
 import android.graphics.*
 import android.graphics.drawable.BitmapDrawable
@@ -2853,7 +2854,10 @@
 
         waitOnUiThread {
             if(resID != 0) {
-                icon = ResourcesCompat.getDrawable(resources, resID, null)
+                try {
+                    icon = ResourcesCompat.getDrawable(resources, resID, null)
+                } catch(e: Resources.NotFoundException) {
+                }
             } else if(filename != null) {
                 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
 
@@ -2867,7 +2871,6 @@
                     if(icon != null) {
                         break
                     }
-
                 }
             } else if(data != null) {
                 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length))