Android : Null pointer exception on bitmap while scrolling

on Sunday, November 2, 2014


I am creating a bitmap which hold Facebook image cropped in a circular shape the code was working fine but wen there is a lot of images in the same activity its giving a null pointer exception while scrolling here is my code



//enter code here
byte[] decodedString = Base64.decode(obj.picture, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
on this line i am getting a null pointer exception
Bitmap circleBitmap = Bitmap.createBitmap(decodedByte.getWidth(), decodedByte.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(decodedByte, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(decodedByte.getWidth() / 2, decodedByte.getHeight() / 2, decodedByte.getWidth() / 2, paint);
holder.civilianImage.setImageBitmap(circleBitmap);


i can see the image presented but while i scroll this error is shown. Any help would be appreciated. And one more thing i getting the image from Facebook but each image is different from the other one in resolution and while cropping the image is losing a lot of it how can i manage this also.


0 comments:

Post a Comment