[Android] BitmapUtil: Prevent NPE on app startup
Geoffrey Métais
git at videolan.org
Fri Mar 30 16:51:16 CEST 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 16 15:37:47 2018 +0100| [aba394305a76c113dc5ee09b0550b50de80d8a6f] | committer: Geoffrey Métais
BitmapUtil: Prevent NPE on app startup
(cherry picked from commit fd16512869c2562a86e5249fc9d2905578d15eee)
> https://code.videolan.org/videolan/vlc-android/commit/aba394305a76c113dc5ee09b0550b50de80d8a6f
---
.../src/org/videolan/vlc/gui/helpers/BitmapUtil.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
index e78194a5b..ba308ee2e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
@@ -100,8 +100,8 @@ public class BitmapUtil {
private static Bitmap fetchPicture(MediaWrapper media) {
final BitmapCache cache = BitmapCache.getInstance();
- Bitmap picture = readCoverBitmap(media.getArtworkURL());
- cache.addBitmapToMemCache(media.getLocation(), picture);
+ final Bitmap picture = readCoverBitmap(media.getArtworkURL());
+ if (picture != null) cache.addBitmapToMemCache(media.getLocation(), picture);
return picture;
}
@@ -114,12 +114,12 @@ public class BitmapUtil {
}
private static Bitmap readCoverBitmap(String path) {
- if (path == null)
- return null;
- Resources res = VLCApplication.getAppResources();
+ if (path == null) return null;
+ final Context ctx = VLCApplication.getAppContext();
+ if (ctx == null) return null;
+ final Resources res = ctx.getResources();
String uri = Uri.decode(path);
- if (uri.startsWith("file://"))
- uri = uri.substring(7);
+ if (uri.startsWith("file://")) uri = uri.substring(7);
Bitmap cover = null;
BitmapFactory.Options options = new BitmapFactory.Options();
int height = res.getDimensionPixelSize(R.dimen.grid_card_thumb_height);
More information about the Android
mailing list