0

I tried using this code for getting imageUri from bitmap that i found here

My code was working well actually, but suddenly it started giving nullpointerexception

Here is my class

public Uri getImageUri(Context inContext, Bitmap inImage) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);  //LogCat shows error at this line
        Log.e("path", path);
        return Uri.parse(path);
}

Here is what logcat says

05-06 09:37:27.190: E/MediaStore(2725): Failed to insert image
05-06 09:37:27.190: E/MediaStore(2725): java.lang.NullPointerException
05-06 09:37:27.190: E/MediaStore(2725):     at android.os.Parcel.readException(Parcel.java:1327)
05-06 09:37:27.190: E/MediaStore(2725):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)
05-06 09:37:27.190: E/MediaStore(2725):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
05-06 09:37:27.190: E/MediaStore(2725):     at android.content.ContentProviderProxy.insert(ContentProviderNative.java:447)
05-06 09:37:27.190: E/MediaStore(2725):     at android.content.ContentResolver.insert(ContentResolver.java:721)
05-06 09:37:27.190: E/MediaStore(2725):     at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:779)
05-06 09:37:27.190: E/MediaStore(2725):     at com.receiver.CustomUploadImages_New.getImageUri(CustomUploadImages_New.java:397)
05-06 09:37:27.190: E/MediaStore(2725):     at com.receiver.CustomUploadImages_New$SaveToDatabase.doInBackground(CustomUploadImages_New.java:245)
05-06 09:37:27.190: E/MediaStore(2725):     at com.receiver.CustomUploadImages_New$SaveToDatabase.doInBackground(CustomUploadImages_New.java:1)
05-06 09:37:27.190: E/MediaStore(2725):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
05-06 09:37:27.190: E/MediaStore(2725):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-06 09:37:27.190: E/MediaStore(2725):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-06 09:37:27.190: E/MediaStore(2725):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
05-06 09:37:27.190: E/MediaStore(2725):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
Community
  • 1
  • 1
Neal Ahluvalia
  • 1,538
  • 1
  • 10
  • 20

1 Answers1

0

Check The Bitmap You Are Passing In The Method Above Because You may be Passing Null bitmap In this Method And Then Run again ... And Method Works Properly... Hope It helps , Thanks

Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • Thanx for your answer. I still don't know what was the problem, but a simple restart of eclipse and my android device solved this problem. But still i am facing this issue when i click more images. Like more than 40 or so.And yes i checked, its not passing a null bitmap. – Neal Ahluvalia May 06 '15 at 08:58
  • are you getting Out of Memory Exception while loading bitmaps ? – Quick learner May 06 '15 at 09:00