In my application I am downloading the image using Picasso and converting that image in to byte array.i am calling below this method to download and convert the image to byte array.
private byte[] convertToByte(String url) {
Picasso.with(list_my_posts.this).load(url).fit().centerCrop().into(img);
Bitmap bitmap=((BitmapDrawable)img.getDrawable()).getBitmap();
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100,stream);
byteArray= stream.toByteArray();
Toast.makeText(getApplicationContext(),"Downloaded Successfully",Toast.LENGTH_LONG).show();
return byteArray;
}
My problem is I am getting error like this.
Log
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap android.graphics.drawable.BitmapDrawable.getBitmap()' on a null object reference
Can anyone help me to solve this issue.