[android-developers] Re: NullPointerException on displaying ImageView of a bitmap

2011-08-26 Thread blake
I'm with Drezden: I don't think that the code you've cited is
necessarily the code that is at fault.  I'd be inclined to look at the
constructor for com.android.databasetest.DatabaseTest

-blake

On Aug 25, 8:54 am, Abhi abhishek.r.sha...@gmail.com wrote:
 Hi

 I have the following piece of code which is resulting in a
 NullPointerException and I am not able to understand why. I am able to
 get the correct size of the bitmap in the Log statement below before
 displaying the image, so up to that point everything is good.

 //result is a byte array which contains the jpeg image

 ByteArrayInputStream inputStream = new ByteArrayInputStream(result);
 b = BitmapFactory.decodeStream(inputStream);

 Log.i(TAG, Size of bitmap is  + b.getWidth() +  x  +
 b.getHeight());

 ImageView imageview1 = (ImageView) findViewById(R.id.ImageV);
 imageview1.setImageBitmap(b);

 The exception I am getting is below :

 08-25 11:46:25.578: ERROR/AndroidRuntime(12564): FATAL EXCEPTION: main
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):
 java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.android.databasetest/
 com.android.databasetest.DatabaseTest}: java.lang.NullPointerException
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
 1821)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
 1842)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.access$1500(ActivityThread.java:132)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.os.Handler.dispatchMessage(Handler.java:99)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.os.Looper.loop(Looper.java:143)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.main(ActivityThread.java:4263)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 java.lang.reflect.Method.invokeNative(Native Method)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 java.lang.reflect.Method.invoke(Method.java:507)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.internal.os.ZygoteInit
 $MethodAndArgsCaller.run(ZygoteInit.java:839)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 dalvik.system.NativeStart.main(Native Method)

 08-25 11:46:25.578: ERROR/AndroidRuntime(12564): Caused by:
 java.lang.NullPointerException
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.databasetest.DatabaseTest.onCreate(DatabaseTest.java:62)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
 1072)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
 1785)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     ... 11 more

 Any help is appreciated.

 Thanks,

 AB

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: NullPointerException on displaying ImageView of a bitmap

2011-08-25 Thread Drezden
What is specifically happening in your onCreate method at line 62?
That's where the null exception is coming from.

Also, you might want to use the BitmapFactory.Options to help in image
creation.  You can easily tweak the options to get image dimensions
without having to create the actual bitmap (see inJustDecodeBounds)
and you can adjust the sample size to put less memory strain on your
application.  Try this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inTempStorage = new byte[16*1024];
options.inJustDecodeBounds = false;

Bitmap b = BitmapFactory.decodeStream(inputStream,null,options);

Then test b to make sure it isn't null before loading it into your
ImageView.



On Aug 25, 10:54 am, Abhi abhishek.r.sha...@gmail.com wrote:
 Hi

 I have the following piece of code which is resulting in a
 NullPointerException and I am not able to understand why. I am able to
 get the correct size of the bitmap in the Log statement below before
 displaying the image, so up to that point everything is good.

 //result is a byte array which contains the jpeg image

 ByteArrayInputStream inputStream = new ByteArrayInputStream(result);
 b = BitmapFactory.decodeStream(inputStream);

 Log.i(TAG, Size of bitmap is  + b.getWidth() +  x  +
 b.getHeight());

 ImageView imageview1 = (ImageView) findViewById(R.id.ImageV);
 imageview1.setImageBitmap(b);

 The exception I am getting is below :

 08-25 11:46:25.578: ERROR/AndroidRuntime(12564): FATAL EXCEPTION: main
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):
 java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.android.databasetest/
 com.android.databasetest.DatabaseTest}: java.lang.NullPointerException
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
 1821)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
 1842)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.access$1500(ActivityThread.java:132)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.os.Handler.dispatchMessage(Handler.java:99)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.os.Looper.loop(Looper.java:143)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.main(ActivityThread.java:4263)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 java.lang.reflect.Method.invokeNative(Native Method)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 java.lang.reflect.Method.invoke(Method.java:507)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.internal.os.ZygoteInit
 $MethodAndArgsCaller.run(ZygoteInit.java:839)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 dalvik.system.NativeStart.main(Native Method)

 08-25 11:46:25.578: ERROR/AndroidRuntime(12564): Caused by:
 java.lang.NullPointerException
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 com.android.databasetest.DatabaseTest.onCreate(DatabaseTest.java:62)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
 1072)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
 1785)
 08-25 11:46:25.578: ERROR/AndroidRuntime(12564):     ... 11 more

 Any help is appreciated.

 Thanks,

 AB

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en