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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:55:32+00:00 2026-06-04T19:55:32+00:00

I’m having some problems selecting an image from my gallery and using that in

  • 0

I’m having some problems selecting an image from my gallery and using that in my application.
I use this intent:

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, ACTIVITY_SELECT_PHOTO);

And that brings me to the gallery where I can pick an image.
But the moment I select one, onActivityResult is called immediately,
while the ACTION_PICK hasn’t finished everything. Well, I guess that’s the problem.
I’ve read I should try to change the launchMode to singleTop on the activity in the manifest but this didn’t work. Or should I change the launchMode of “ACTION_PICK”-activity?
And is this even possible?

final static int ACTIVITY_SELECT_PHOTO = 0;
final static int ACTIVITY_CAMERA_PHOTO = 1;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 
    Log.d("onActivityresult", "req = " + requestCode + ", result = " + resultCode);
    switch(requestCode) { 
    case ACTIVITY_SELECT_PHOTO:
        if(resultCode == RESULT_OK){  

            Uri selectedImageUri=imageReturnedIntent.getData();
            String actualPath=getRealPathFromURI(selectedImageUri);
            File file=new File(actualPath);
            Bitmap b=decodeFile(file); //this is new bitmap which you can use for your purpose 

            try {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                b.compress(Bitmap.CompressFormat.PNG, 55, os);
                compressedByteArray = os.toByteArray();
                iv.setImageBitmap(b);
                currentUser.put("picture", compressedByteArray);
                Toast t = Toast.makeText(this, "Uploading picture...", Toast.LENGTH_LONG);
                t.show();
                currentUser.save();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    case ACTIVITY_CAMERA_PHOTO:
        if(resultCode == RESULT_OK){

            Bundle extras = imageReturnedIntent.getExtras();

            //THE LINE BELOW THIS ONE GIVES NULLPOINTEREX WHICH IS OBVIOUS BECAUSE IT's ANOTHER //CASE      
            Bitmap bmp = (Bitmap)extras.get("data");
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 55, os);
            compressedByteArray = os.toByteArray();
            bmp = BitmapFactory.decodeByteArray(compressedByteArray, 0, compressedByteArray.length);
            iv.setImageBitmap(bmp);
            currentUser.put("picture", compressedByteArray);

        }
        try {
            Toast t = Toast.makeText(this, "Uploading picture...", Toast.LENGTH_LONG);
            t.show();
            currentUser.save();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

ResultCode = -1 (so RESULT_OK)
but it gives me an error:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://media/external/images/media/173 }} to activity {com.tapazz/com.tapazz.ShowProfileActivity}: java.lang.NullPointerException

The nullPointerException comes from a different RequestCode (see “THIS LINE” above)

The app stops, but when I restart it, I see that it has picked the photo like it should do

  • 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-04T19:55:33+00:00Added an answer on June 4, 2026 at 7:55 pm

    This may or may not be related, but your switch() statement doesn’t break after each case. So, if it enters the ACTIVITY_SELECT_PHOTO case, it will also process the ACTIVITY_CAMERA_PHOTO as well

    switch() {
       case 1:
          break;
    
       case 2:
          break;
    }
    

    Notice that you always need a break; statement at the end of each case.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
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 a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and

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.