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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:36:46+00:00 2026-06-06T05:36:46+00:00

my first question here! I have a problem with a piece of code that

  • 0

my first question here! I have a problem with a piece of code that starts a camera intent with the extra output options and then on activity result tries to resize that image. what is happening is that a nullpointer exception gets thrown in the resize function at the callback.

The original large picture is still saved on the file system, as I can access that from the filesystem.

The original camera jpeg is 2560×1920 in size and the phone in use is a google nexus one.

I have no clear idea asto why the resize is not working, anyone have any insight?

Here’s some code:

The takePicture function that also creates the dummy file:

        public boolean takePicture( ) {

            Log.e(TAG, "takePicture interface function");
            String FileUri = Environment.getExternalStorageDirectory()  + "/samples/";
            File file = new File(FileUri,"picture"+ pictureNumber +".jpg");
            try {
                file.createNewFile();
                } catch (IOException e) {
                e.printStackTrace();
                }
                Uri outputFileUri = Uri.fromFile(file);

            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
            Log.e(TAG, "intent started");
            return true;
        }

The on activity result callback function:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

        // handle the camera request returns and handle back button in camera.

        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_CANCELED ) {
            Toast toast = Toast.makeText(this,"Canceled, no picture taken.", 1000);
            toast.show();
            return;
           }

        else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK ) { 

            Log.e(TAG, "Camera intent return");

            Bitmap scaledphoto = null;
            int height = 300;
            int width = 300;    

            Bitmap photo = BitmapFactory.decodeFile( APP_DATA_PATH + "/samples/picture" + pictureNumber + ".jpg" );
            Log.e(TAG, "Picture fetched");

            scaledphoto = Bitmap.createScaledBitmap(photo, height, width, true);


            Log.e(TAG, "Picture scaled");

            saveImageToFile(scaledphoto, "picture" + pictureNumber + ".jpg");


            Log.e(TAG, "Scaled picture saved");

            myWebView.loadUrl("javascript:pictureTaken(\""+ pictureLoc + "\")");

            pictureNumber++;

And here’s the LogCat:

06-21 14:59:13.496: E/AndroidRuntime(6130): FATAL EXCEPTION: main
06-21 14:59:13.496: E/AndroidRuntime(6130): java.lang.RuntimeException: Failure     delivering result ResultInfo{who=null, request=1888, result=-1, data=null} to activity {test.test/test.test.CameraIntentTestActivity}: java.lang.NullPointerException
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.app.ActivityThread.access$1100(ActivityThread.java:123)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.os.Looper.loop(Looper.java:137)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at java.lang.reflect.Method.invokeNative(Native Method)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at java.lang.reflect.Method.invoke(Method.java:511)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-21 14:59:13.496: E/AndroidRuntime(6130):     at dalvik.system.NativeStart.main(Native Method)
06-21 14:59:13.496: E/AndroidRuntime(6130): Caused by: java.lang.NullPointerException
06-21 14:59:13.496: E/AndroidRuntime(6130):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:432)
  • 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-06T05:36:50+00:00Added an answer on June 6, 2026 at 5:36 am

    Change

    Bitmap photo = BitmapFactory.decodeFile( APP_DATA_PATH + "/samples/picture" + pictureNumber + ".jpg" );
    

    To

      Bitmap photo = (Bitmap) data.getExtras().get("data");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick question here. I know that the cakePHP find('first') function returns
My first question here, hopefully I'm not doing it wrong. My problem is that
Bit of an open-ended question here, so I'll outline the problem first. We have
its my first question here on this site. well i have a problem regarding
this is my first question.. so, here we go. i have a site, 100%
Sorry, this's my first time to ask a question here. So, I don't have
this is my first time posting here, I have a question which I have
First question here: it is a very short yet fundamental thing in Java that
this is my first question here :) I know that I should not check
I have a piece of templated code that is never run, but is compiled.

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.