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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:25:17+00:00 2026-06-03T03:25:17+00:00

I am trying to save a picture in an Android application. Here is my

  • 0

I am trying to save a picture in an Android application. Here is my callback function:

ShutterCallback myShutterCallback = new ShutterCallback(){

    @Override
    public void onShutter() {
        Log.d(TAG, "shutter callback");
        
    }};


PictureCallback myPictureCallback_RAW = new PictureCallback(){

    @Override
    public void onPictureTaken(byte[] arg0, Camera arg1) {
        Log.d(TAG, "raw callback");
        
    }};
    
PictureCallback myPictureCallback_JPG = new PictureCallback(){

    @Override
    public void onPictureTaken(byte[] arg0, Camera arg1) {
        // TODO Auto-generated method stub
        Bitmap bitmapPicture 
            = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);  
        
        ContentValues values = new ContentValues();
        values.put(Images.Media.TITLE, "title");
        values.put(Images.Media.BUCKET_ID, "test");
        values.put(Images.Media.DESCRIPTION, "test Image taken");
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        
        Uri uriTarget = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

        OutputStream imageFileOS;
        try {
            imageFileOS = getContentResolver().openOutputStream(uriTarget);
            imageFileOS.write(arg0);
            imageFileOS.flush();
            imageFileOS.close();
            
            Toast.makeText(CameraView.this, 
                    "Image saved: " + uriTarget.toString(), 
                    Toast.LENGTH_LONG).show();
            
        } catch (FileNotFoundException e) {
            Log.d(TAG, "file not found " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            Log.d(TAG, "io exception " + e.getMessage());
            e.printStackTrace();
        }

        //camera.startPreview();
        finish();
    }
};

The problem is, for several different types of phones, I get a NullPointerException at this line:

imageFileOS = getContentResolver().openOutputStream(uriTarget);

Has anyone run into this before?

Edit – Stack trace

04-24 11:52:03.979: E/AndroidRuntime(12695): FATAL EXCEPTION: main
04-24 11:52:03.979: E/AndroidRuntime(12695): java.lang.NullPointerException
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:465)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.content.ContentResolver.openOutputStream(ContentResolver.java:361)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.content.ContentResolver.openOutputStream(ContentResolver.java:337)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at com.appfury.grafighters.CameraView$4.onPictureTaken(CameraView.java:234)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:536)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.os.Looper.loop(Looper.java:150)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at android.app.ActivityThread.main(ActivityThread.java:4263)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at java.lang.reflect.Method.invoke(Method.java:507)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 11:52:03.979: E/AndroidRuntime(12695):    at dalvik.system.NativeStart.main(Native Method)
  • 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-03T03:25:19+00:00Added an answer on June 3, 2026 at 3:25 am

    It turns out the problem was specific to HTC devices. I resolved the problem by saving the image files in the DCIM folder on the device, but not using getContentResolver to get the path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everyone. I'm trying to save a picture with android to the public pictures directory
I have an Android application where I'm trying to send a picture to a
I am trying to write an Android application that will take a picture, put
I'm trying to create an application that can use the android as a fax
I'm trying to capture the picture I'm getting from webview.capturePicture() to save it to
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picture_choice_activity); Button takePictureButton = (Button)findViewById(R.id.takePictureButton); takePictureButton.setOnClickListener(new OnClickListener()
I am trying to upload a picture, and save it in database. If I
I'm taking a picture using my own camera and trying to save the result
I'm taking a picture using my own camera and trying to save the result
Trying to save output from this script to a file based on a cell

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.