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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:51:12+00:00 2026-06-09T09:51:12+00:00

I have made two buttons. One that opens the camera and one that opens

  • 0

I have made two buttons. One that opens the camera and one that opens the gallery. The camera one works fine but the gallery one does not… It opens but when I choose a picture from the gallery the application closes unexpectedly.

package com.example.me;

import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class MainActivity extends Activity implements View.OnClickListener{


Button b;
ImageView iv;
Intent i;
final static int cameraData = 0;
Bitmap bmp;
private static final int SELECT_IMAGE = 1;
Button clickk;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initialize();
    InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
    bmp = BitmapFactory.decodeStream(is);
}


private void initialize() {
    // TODO Auto-generated method stub
    iv = (ImageView) findViewById (R.id.imageView1);
    b = (Button) findViewById (R.id.btakePic);
    clickk = (Button) findViewById (R.id.bChose);
    b.setOnClickListener(this);
    clickk.setOnClickListener(this);
}


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()){

    case R.id.btakePic:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);
        break;
    case R.id.bChose:
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);//
        startActivityForResult(Intent.createChooser(intent, "Select  Picture"),SELECT_IMAGE);
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);
    }

}
}   

Here are logs:

08-05 11:30:19.455: E/ActivityThread(5576): Activity           com.android.internal.app.ChooserActivity has leaked IntentReceiver   com.android.internal.app.ResolverActivity$1@412fd3e0 that was originally registered here.  Are you missing a call to unregisterReceiver()?
08-05 11:30:19.455: E/ActivityThread(5576): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@412fd3e0 that was originally registered here. Are you missing a call to unregisterReceiver()?
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1099)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1086)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1080)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:348)
08-05 11:30:19.455: E/ActivityThread(5576):     at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
08-05 11:30:19.455: E/ActivityThread(5576):     at    com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:101)
08-05 11:30:19.455: E/ActivityThread(5576):     at    com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.Activity.performCreate(Activity.java:4465)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.os.Looper.loop(Looper.java:137)
08-05 11:30:19.455: E/ActivityThread(5576):     at android.app.ActivityThread.main(ActivityThread.java:4514)
08-05 11:30:19.455: E/ActivityThread(5576):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:30:19.455: E/ActivityThread(5576):     at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:30:19.455: E/ActivityThread(5576):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-05 11:30:19.455: E/ActivityThread(5576):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-05 11:30:19.455: E/ActivityThread(5576):     at dalvik.system.NativeStart.main(Native Method)
08-05 11:30:19.471: D/OpenGLRenderer(5576): Flushing caches (mode 1)
08-05 11:30:42.932: D/AndroidRuntime(5576): Shutting down VM
08-05 11:30:42.932: W/dalvikvm(5576): threadid=1: thread exiting with uncaught exception   (group=0x40be41f8)
08-05 11:30:42.932: E/AndroidRuntime(5576): FATAL EXCEPTION: main
08-05 11:30:42.932: E/AndroidRuntime(5576): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/774 }} to activity {com.example.me/com.example.me.MainActivity}: java.lang.NullPointerException
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2994)
08-05 11:30:42.932: E/AndroidRuntime(5576):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3037)
08-05 11:30:42.932: E/AndroidRuntime(5576):     at android.app.ActivityThread.access$1100(ActivityThread.java:128)
08-05 11:30:42.932: E/AndroidRuntime(5576):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1191)
08-05 11:30:42.932: E/AndroidRuntime(5576):     at android.os.Handler.dispatchMessage(Handler.java:99)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at android.os.Looper.loop(Looper.java:137)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at android.app.ActivityThread.main(ActivityThread.java:4514)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-05 11:30:42.932: E/AndroidRuntime(5576):   at java.lang.reflect.Method.invoke(Method.java:511)
  08-05 11:30:42.932: E/AndroidRuntime(5576):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at dalvik.system.NativeStart.main(Native Method)
  08-05 11:30:42.932: E/AndroidRuntime(5576): Caused by: java.lang.NullPointerException
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at com.example.me.MainActivity.onActivityResult(MainActivity.java:72)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at android.app.Activity.dispatchActivityResult(Activity.java:4649)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2990)
 08-05 11:30:42.932: E/AndroidRuntime(5576):    ... 11 more

Here is what I have now. It still does not work. I’m guessing I’m supposed to put something between the camera result and the gallery result?

     @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     // TODO Auto-generated method stub
     super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == RESULT_OK){
         Bundle extras = data.getExtras();
         bmp = (Bitmap) extras.get("data");
         iv.setImageBitmap(bmp);
         if (requestCode == SELECT_IMAGE) {
            if(resultCode == RESULT_OK){  
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Cursor cursor = getContentResolver().query(selectedImage,   filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();
                Log.i(myTag, filePath); 
                File imgFile = new File(filePath);
                //Get your image out of the file
                //do with it what you will.
                Bundle extras1 = data.getExtras();
                bmp = (Bitmap) extras1.get("data");
                iv.setImageBitmap(bmp);

Also is the my tag supposed to be a string?

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == cameraData)
    if (resultCode == RESULT_OK)   {
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);



        if (requestCode == SELECT_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            ImageView imageView = (ImageView)   findViewById(R.id.imageView1);
               imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  • 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-09T09:51:15+00:00Added an answer on June 9, 2026 at 9:51 am

    You need to handle the gallery differently than the camera in your onActivityResult(). Here is a rough example of what you’ll need to do to handle the choose image from gallery case.

    if (requestCode == SELECT_IMAGE) {
        if(resultCode == RESULT_OK){  
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
    
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();
    
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.i(myTag, filePath); 
            File imgFile = new File(filePath);
            //Get your image out of the file
            //do with it what you will.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IN my apllication i have three Views One,Two,Three. In all view I made one
I have two nib files, one that will open at startup and another that
I have two UITextFields in the App as IBOutlets and I have made a
I have made a list view containing two childs. Now i am trying to
I have made a simple test application for the issue, two winforms each containing
I have two branches: trunk, production. I have found a problem in trunk, made
I have these two images. And... I made them into graysclae images and then
I have made a jQuery toggle for a menu that I had in mind.
I have made a code that read data from flash Nand (without filesystem). fd
I have made a cart and the cart has remove item button, but 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.