Issue
I am converting a Url to Uri in the following way
imgUrl = intent.getStringExtra(getString(R.string.selected_image));
Log.d(TAG, "Image URL" + imgUrl);
imageUri = Uri.parse(imgUrl) ;
Log.d(TAG, "Image URI" + imageUri);
then passing it to this function
BackgroundImageResize backgroundImageResize = new BackgroundImageResize(bitmap);
backgroundImageResize.execute(imageUri);
and BackgroundImageResize takes arguments as
public class BackgroundImageResize extends AsyncTask<Uri, Integer, byte[]>
now this method
Log.d(TAG, "doInBackground: megabytes before compression: " + mBitmap.getByteCount() / 1000000 );
bytes = getBytesFromBitmap(mBitmap, 100);
Log.d(TAG, "doInBackground: megabytes before compression: " + bytes.length / 1000000 );
is returning this error
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getByteCount()' on a null object reference
in previous discussions with a really smart person, it has been concluded that, maybe, the Uri is incorrect
How do I pass the correct Uri ?
this is the doInBackground() just in case
@Override
protected byte[] doInBackground(Uri... params) {
Log.d(TAG, "doInBackground: started.");
if(mBitmap == null){
try{
mBitmap = MediaStore.Images.Media.getBitmap(NextActivity.this.getContentResolver(), params[0]);
}catch (IOException e){
Log.e(TAG, "doInBackground: IOException: " + e.getMessage());
}
}
byte[] bytes = null;
Log.d(TAG, "doInBackground: megabytes before compression: " + mBitmap.getByteCount() / 1000000 );
bytes = getBytesFromBitmap(mBitmap, 100);
Log.d(TAG, "doInBackground: megabytes before compression: " + bytes.length / 1000000 );
return bytes;
}
I suspect that this line of code
mBitmap = MediaStore.Images.Media.getBitmap(NextActivity.this.getContentResolver(), params[0]);
is not doing it's job :P
Solution
Please add the 2 Logs with the ++++++++++++ lines in your doInBackGround() and post your Logcat:
@Override
protected byte[] doInBackground(Uri... params) {
Log.d(TAG, "doInBackground: started.");
Log.d(TAG, "+++++++++++++ params[0]: " + params[0]);
if(mBitmap == null){
try{
mBitmap = MediaStore.Images.Media.getBitmap(NextActivity.this.getContentResolver(), params[0]);
}catch (IOException e){
Log.e(TAG, "doInBackground: IOException: " + e.getMessage());
}
}
Log.d(TAG, "+++++++++++++ mBitmap: " + mBitmap);
byte[] bytes = null;
Log.d(TAG, "doInBackground: megabytes before compression: " + mBitmap.getByteCount() / 1000000 );
bytes = getBytesFromBitmap(mBitmap, 100);
Log.d(TAG, "doInBackground: megabytes before compression: " + bytes.length / 1000000 );
return bytes;
}
Answered By - Locdoc01
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.