attaching image from gallery fc on repeatedly attaching the same image
<p>i am attaching the image from gallery and show it other view i attach 2 times success full but on next trial of attaching image from gallery force close my application,why?i am very surprise why its happening?</p>

<p>code for open galery</p>

<pre><code>            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,
                    "Select Picture"), SELECT_PICTURE);
</code></pre>

<p>code for selecting path is...</p>

<pre><code>       public void onActivityResult(int requestCode, int resultCode, Intent data) {

            if (requestCode == CAMERA_PIC_REQUEST||requestCode == SELECT_PICTURE) {
                try{
                     selectedImageUri = data.getData();

                    //OI FILE Manager
                    filemanagerstring = selectedImageUri.getPath();

                    //MEDIA GALLERY
                   selectedImagePath = getPath(selectedImageUri);

                    //DEBUG PURPOSE - you can delete this if you want
                    if(selectedImagePath!=null){

                         Intent i=new Intent(MainMenu.this,Imageprview.class);
                          startActivity(i);
                          System.out.println(selectedImagePath);
                    }

                    else
                        System.out.println("selectedImagePath is null");
                    if(filemanagerstring!=null)
                        System.out.println(filemanagerstring);
                    else System.out.println("filemanagerstring is null");

                    //NOW WE HAVE OUR WANTED STRING
                    if(selectedImagePath!=null)
                        System.out.println("selectedImagePath is the right one for you!");
                    else
                        System.out.println("filemanagerstring is the right one for you!");
                }catch (NullPointerException e) {
                    // TODO: handle exception
                }               }
        }

        //UPDATED!
           public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if(cursor!=null)
        {
            //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
            //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        else return null;
    }
</code></pre>

<p>code for displaying it to other activity is..</p>

<pre><code>        setContentView(R.layout.imagepreview);
    ImageView iv=(ImageView)findViewById(R.id.imageView1);
    bmImg = BitmapFactory.decodeFile(MainMenu.selectedImagePath);
    iv.setImageBitmap(bmImg);
</code></pre>

<p>it attach two or one time but on next trial of one after other it force close...</p>

<p>thanks in advance</p>
