Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:33+00:00 2026-06-16T00:45:33+00:00

I’m trying to capture image and save it in gallery. For that in onCreate

  • 0

I’m trying to capture image and save it in gallery. For that in onCreate my code

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    imageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intent, TAKE_PICTURE);

and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK && requestCode == TAKE_PICTURE) {
        Log.v("data", "data: " + data);
        Bundle extras = data.getExtras();
        if (extras.containsKey("data")) {
            bitmap = (Bitmap) extras.get("data");
            // ByteArrayOutputStream baos = new ByteArrayOutputStream();
            // bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
            // byte[] image = baos.toByteArray();
            if (bitmap != null) {
                // BitmapFactory.Options options = new
                // BitmapFactory.Options();
                // options.inSampleSize = 5;
                // Bitmap myImage = BitmapFactory.decodeByteArray(image, 0,
                // image.length, options);
                imageView.setImageBitmap(bitmap);
            }
        } else {
            Toast.makeText(getBaseContext(), "Please capture again", Toast.LENGTH_LONG).show();
        }
        showPopUpForUpload();
    }
}

Now I’m able to capture image, but after that I’m getting error

12-17 15:28:56.090: E/AndroidRuntime(4684): FATAL EXCEPTION: main
12-17 15:28:56.090: E/AndroidRuntime(4684): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=null} to activity {com.example.fashiongirl/com.example.fashiongirl.HomeActivity}: java.lang.NullPointerException
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2744)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2787)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread.access$2000(ActivityThread.java:122)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1032)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.os.Looper.loop(Looper.java:132)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread.main(ActivityThread.java:4025)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at java.lang.reflect.Method.invokeNative(Native Method)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at java.lang.reflect.Method.invoke(Method.java:491)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at dalvik.system.NativeStart.main(Native Method)
12-17 15:28:56.090: E/AndroidRuntime(4684): Caused by: java.lang.NullPointerException
12-17 15:28:56.090: E/AndroidRuntime(4684):     at com.example.fashiongirl.HomeActivity.onActivityResult(HomeActivity.java:47)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.Activity.dispatchActivityResult(Activity.java:4541)
12-17 15:28:56.090: E/AndroidRuntime(4684):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2740)
12-17 15:28:56.090: E/AndroidRuntime(4684):     ... 11 more

The null pointer exception is on line

Bundle extras = data.getExtras();

So what is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:45:34+00:00Added an answer on June 16, 2026 at 12:45 am

    I think its a problem of Android version 4.0 +.

    Just try to remove,

    File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    imageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    

    When you call Capture intent. Now your resulted bundle onActivityResult() is not NULL.

    Actually, When you are giving MediaStore.EXTRA_OUTPUT parameter to Camera Intent then camera application doesn’t callback with bundled data. (I find this issues in Android 4.0 +)

    You have to get the Image file from Uri which you set as MediaStore.EXTRA_OUTPUT parameter.

    Update:

    Or use below pathFromUri() method and pass Uri which you are set to camera intent and get the Real File Path, now for this you don’t have to use Bundle extras = data.getExtras();

    private String pathFromUri(Uri imageUri) {
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(imageUri, filePathColumn,
                    null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        return filePath ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.