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

  • Home
  • SEARCH
  • 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 8044077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:06:49+00:00 2026-06-05T05:06:49+00:00

My app has null pointer exceptions when it tries to take a picture and

  • 0

My app has null pointer exceptions when it tries to take a picture and with the camera.
My app calls the camera thusly:

        //go to camera app.

        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile()));

        //open camera. Take picture. 

        startActivityForResult(intent, PIC_ONE);

and the onresult code is:

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
    if (requestCode == PIC_ONE)
            {



                    //prevent null pointer
                    if(data.getData()!=null){
                        uri1 = data.getData();
                        File f = new File(getPath(uri1));//<-NULL POINTER EXCEPTION
                        //...do stuff
    }

This causes a nullpointer exception, as shown above. getPath causes this null pointer. getPath() is shown below.
This method is not retrieving the image from the mediastore as it should.

public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        startManagingCursor(cursor);
        if(cursor!=null){
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return  cursor.getString(column_index);
        }
        else return null;
    }

Below is the logcat:

    06-07 22:53:59.650: ERROR/AndroidRuntime(3935): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { act=inline-data dat=file:///mnt/sdcard/image.tmp typ=image/jpeg (has extras) }} to activity {com.myapp.myactivity/myactivity.java}: java.lang.NullPointerException
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2553)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.app.ActivityThread.access$2000(ActivityThread.java:121)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.os.Looper.loop(Looper.java:138)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at android.app.ActivityThread.main(ActivityThread.java:3701)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at java.lang.reflect.Method.invokeNative(Native Method)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at java.lang.reflect.Method.invoke(Method.java:507)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at dalvik.system.NativeStart.main(Native Method)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935): Caused by: java.lang.NullPointerException
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at java.io.File.fixSlashes(File.java:205)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at java.io.File.init(File.java:189)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at java.io.File.<init>(File.java:139)
06-07 22:53:59.650: ERROR/AndroidRuntime(3935):     at com.myapp.myactivity.java.onActivityResult(myactivity.java:928)

The strange thing is this app works fine on an Xperia X10, but on newer phones including Xperia acro it has this null pointer. I have researched it and it seems the problem could be caused because the camera app is too chunky and causes the initial activity to finish.

So I overrode these two methods:

 @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (uri1 != null) {
            outState.putString("cameraImageUri1", uri1.toString());
        }

    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (savedInstanceState.containsKey("cameraImageUri1")) {
            uri1 = Uri.parse(savedInstanceState.getString("cameraImageUri1"));
        }


        Log.v("THIS ACTIVITY","has called onrestore...");
    }

onRestoreInstanceState is never even called during the picture taking and finishing process. So I dont know what is happening. Why is this null pointer being called

  • 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-05T05:06:51+00:00Added an answer on June 5, 2026 at 5:06 am
            if (data != null) {
                    File myFile;
    
                    Uri selectedImageUri = data.getData();
                    String filemanagerstring = selectedImageUri.getPath();
                    String selectedImagePath = getPath(selectedImageUri);
                    if (selectedImagePath != null)
                        myFile = new File(selectedImagePath);
                    else if (filemanagerstring != null)
                        myFile = new File(filemanagerstring);
                     } 
    

    //here getPath method

    public String getPath(Uri uri) {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            if (cursor != null) {
                int column_index = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            } else
                return null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting null pointer exceptions when I try to initialize Button and EditText objects
In my app in android I need to check if a variable has been
My app has not caught up to the new changes in facebook's oauth. Before,
I have a null pointer on a button that I need to take me
Suddenly my buttons cause null pointer exceptions. I have not changed any code in
My app has these parts A. Main activity B. Widget provider C. Sync Adapter
My app has been in the AppStore for a couple of months now and
My app has this one screen requires login, should I make a comment for
My app has stopped working on the emulatorUnfortunately. I have the logcat with me,
My app has an RSS tableView and at another page a WebView. I can

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.