]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Work around Android bug causing crashes.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 5 Aug 2017 08:04:57 +0000 (10:04 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 5 Aug 2017 08:04:57 +0000 (10:04 +0200)
src/com/hughes/android/dictionary/DictionaryActivity.java

index 008b57de6c1ef6869612267e22177b1e79829a63..c4d2ddae81a926ede0ede7237abe1c3a953823e1 100644 (file)
@@ -1473,13 +1473,18 @@ public class DictionaryActivity extends ActionBarActivity {
         }
 
         private void getMetrics() {
+            float scale = 1;
             // Get the screen's density scale
             // The previous method getResources().getDisplayMetrics()
             // used to occasionally trigger a null pointer exception,
             // so try this instead.
-            DisplayMetrics dm = new DisplayMetrics();
-            getWindowManager().getDefaultDisplay().getMetrics(dm);
-            final float scale = dm.density;
+            // As it still crashes, add a fallback
+            try {
+                DisplayMetrics dm = new DisplayMetrics();
+                getWindowManager().getDefaultDisplay().getMetrics(dm);
+                scale = dm.density;
+            } catch (NullPointerException e)
+            {}
             // Convert the dps to pixels, based on density scale
             mPaddingDefault = (int) (PADDING_DEFAULT_DP * scale + 0.5f);
             mPaddingLarge = (int) (PADDING_LARGE_DP * scale + 0.5f);