Reputation: 1047
I have the following code where I try to rescale a bitmap:
FileInputStream stream = new FileInputStream(new File(getCachePath(context), makeCacheFileName(uri)));
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
value = BitmapFactory.decodeStream(stream, null, o);
value = Bitmap.createScaledBitmap(
value, // bitmap to resize
o.outWidth, // new width
o.outHeight, // new height
true); // bilinear filtering
stream.close();
The log is the following:
01-04 16:24:18.101: E/AndroidRuntime(27524): FATAL EXCEPTION: main
01-04 16:24:18.101: E/AndroidRuntime(27524): java.lang.NullPointerException
01-04 16:24:18.101: E/AndroidRuntime(27524): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:344)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.network.ImageThreadLoader$DiskCache.get(ImageThreadLoader.java:295)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.network.ImageThreadLoader.loadImageFromCache(ImageThreadLoader.java:185)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.products.ProductListAdapter.switchImages(ProductListAdapter.java:119)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.products.ProductListAdapter.access$0(ProductListAdapter.java:79)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.products.ProductListAdapter$1.run(ProductListAdapter.java:73)
01-04 16:24:18.101: E/AndroidRuntime(27524): at android.os.Handler.handleCallback(Handler.java:587)
01-04 16:24:18.101: E/AndroidRuntime(27524): at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 16:24:18.101: E/AndroidRuntime(27524): at android.os.Looper.loop(Looper.java:130)
01-04 16:24:18.101: E/AndroidRuntime(27524): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-04 16:24:18.101: E/AndroidRuntime(27524): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 16:24:18.101: E/AndroidRuntime(27524): at java.lang.reflect.Method.invoke(Method.java:507)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-04 16:24:18.101: E/AndroidRuntime(27524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-04 16:24:18.101: E/AndroidRuntime(27524): at dalvik.system.NativeStart.main(Native Method)
How can I solve my problem?
Upvotes: 0
Views: 759
Reputation: 3452
Nick, BitmapFactory.decodeStream must be returning null which means it's failing to decode the stream. Possibly the value in the file is bad or you were unable to open the file. Check 'stream' for null.
Upvotes: 1