user971741
user971741

Reputation:

NullPointerException while retrieving image form camera activity

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }
}

While Trying to save my image from Camera activity from here i am getting the following error at the last line of the function i.e. imageView.setImageBitmap(photo);

11-03 03:27:21.928: E/AndroidRuntime(27303): Caused by: java.lang.NullPointerException
11-03 03:27:21.928: E/AndroidRuntime(27303):    at com.example.echelon.MainActivity.onActivityResult(MainActivity.java:37)
11-03 03:27:21.928: E/AndroidRuntime(27303):    at android.app.Activity.dispatchActivityResult(Activity.java:5293)
11-03 03:27:21.928: E/AndroidRuntime(27303):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3443)
11-03 03:27:21.928: E/AndroidRuntime(27303):    ... 11 more

To make sure on my sid ethrough debug i have make sure that the photo is not null and contains data and shows this in the object description: android.graphics.Bitmap@414b2518

I have also find on here that there is a bug in Samsung devices, if the bug is related to samsung OS than i am not actually using one, I am using Cyanogen Mod in a Samsung device. can someone please help me out here?

Upvotes: 0

Views: 64

Answers (1)

ssantos
ssantos

Reputation: 16526

Chances are that the image is correctly been retrieved from camera, but your imageView object is null. You should do somewhere before accessing it something like this.-

imageView = (ImageView) findViewById(R.id.yourImageId);

Also, make sure you're not shadowing the instance variable imageView redefining it in another method (such as onCreate) like this.-

ImageView imageView = (ImageView) findViewById(R.id.yourImageId);

Upvotes: 1

Related Questions