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 6177697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:19:17+00:00 2026-05-24T00:19:17+00:00

I need to take a photo with the camera using an activity. In my

  • 0

I need to take a photo with the camera using an activity. In my onActivityResult I am able to retrieve an uri, but I cannot get the file of this uri by using the File constructor. My intent looks like this:

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

I use the global defined “imageURICamera” in onActivityResult. I think that the problem has something to do with the Uri not having the proper attributes as the documentation for the file constructor states that:

“Constructs a new File using the path of the specified URI. uri needs to be an absolute and hierarchical Unified Resource Identifier with file scheme and non-empty path component, but with undefined authority, query or fragment components”

My onActivityResult looks like this at the moment:

 Uri u = imageURICamera;
 getContentResolver().notifyChange(u, null);
 ContentResolver cr = getContentResolver();
 Bitmap bm;
 try {
    bm = android.provider.MediaStore.Images.Media.getBitmap(cr, u);
    String path = getRealPathFromURI(u);
    File f = new File(path);

When i try to query the contentProvider for the path i get the following logcat output:

   07-25 20:04:04.310: ERROR/AndroidRuntime(16438): FATAL EXCEPTION: main
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {tod.dosetracker/tod.dosetracker.ImageViewerActivity}: java.lang.NullPointerException
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  android.os.Handler.dispatchMessage(Handler.java:99)
   07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at       android.os.Looper.loop(Looper.java:123)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.main(ActivityThread.java:3691)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at java.lang.reflect.Method.invoke(Method.java:507)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at dalvik.system.NativeStart.main(Native Method)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438): Caused by: java.lang.NullPointerException
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at tod.dosetracker.ImageViewerActivity.getRealPathFromURI(ImageViewerActivity.java:315)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at tod.dosetracker.ImageViewerActivity.onActivityResult(ImageViewerActivity.java:251)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  android.app.Activity.dispatchActivityResult(Activity.java:3934)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
  07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     ... 11 more
  07-25 20:04:04.315: ERROR/(2696): Dumpstate > /data/log/dumpstate_app_error
  • 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-05-24T00:19:19+00:00Added an answer on May 24, 2026 at 12:19 am

    You already have specified this file should be saved to pic.jpg in your code

    File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    

    You don’t need to do anything more. You should be able to use it directly without saving in the activity result callback.

    You can improve your intent launch code with a timestamp for the image.

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String fileName = dateFormat.format(new Date()) + ".jpg";
    
    // or use timestamp e.g String fileName = System.currentTimeMillis()+".jpg";
    
    File photo = new File(Environment.getExternalStorageDirectory(), fileName);
    
    Intent cameraintent = new Intent("android.media.action.IMAGE_CAPTURE");
    cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    startActivityForResult(cameraintent, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for my android application,I need to take a photo with the built-in camera and
I need to take an existing xml file, and modify just a few attributes
I need to push an intent to default camera application to make it take
I am using the image picker to take a photo and then go to
I don't need to take pictures or access the iPhone photo album. I simply
I need a method which will take an *.jpg image file and upload it
I'm using the UIImagePickerController to take a photo and then upload the photo to
I need to take a photo someone has uploaded through a form, resize, merge
i'm building an application in which i need to take a photo from a
I have an activity A where I'm building my own camera.In this activity the

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.