Null pointer exception while decoding bitmap image
<p>I am trying to implement the following task:</p>

<ol>
<li>Take an Image</li>
<li>Store it in sd card and save the path in a String.</li>
</ol>

<p>code:</p>

<pre><code>public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data) 
    {
       if (resultCode == Activity.RESULT_OK) 
       {
           if (requestCode == RESULT_CAMERA_SELECT)
           {
               try 
               {
                   photo = null;
                   saveImage();
               }
               catch (IOException e) 
               {
                   e.printStackTrace();
               }
           }
       }


public static int calculateInSampleSize(
                BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height &gt; reqHeight || width &gt; reqWidth) {
            if (width &gt; height) {
                inSampleSize = Math.round((float)height / (float)reqHeight);
            } else {
                inSampleSize = Math.round((float)width / (float)reqWidth);
            }
        }
        return inSampleSize;
    }


 public void saveImage() throws IOException
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            FileInputStream is2 = new FileInputStream(new File(myReceipt.filename));
            BitmapFactory.decodeStream(is2 ,null, options);
            // Here is2 get file with width of pic as 2000*1500 etc

            options.inSampleSize = calculateInSampleSize(options, 100, 100);

            options.inJustDecodeBounds = false;

// PROBLEM EXISTS AT THIS POINT. imageBitmap is returned as null.....


  Bitmap imageBitmap = BitmapFactory.decodeStream(is2 ,null, options);
            imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 100, 100, false);

            try{

                        photo = this.createFile(fileName, ".jpg");
                        thumbFileName = photo.getAbsolutePath();
                        Uri uri = Uri.fromFile(photo);

                        try {
                               FileOutputStream out = new FileOutputStream(photo);
                               imageBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                                } catch (Exception e) {
                               e.printStackTrace();
                                }
                                is2.close();
                                photo = null;
                                imageBitmap = null;
                                imageView.setImageURI(uri);
                            }catch(Exception e)
                            {
                                displayAlert("Can't create file to take picture!","SD Card Error");
                            }

        }
</code></pre>

<p>According to the code, I am taking an image, then making a thumbimage to show it in an image view and also storing this thumbImage. But error occurs at</p>

<pre><code>  Bitmap imageBitmap = BitmapFactory.decodeStream(is2 ,null, options);
</code></pre>

<p>it returns null. Can anyone explain what is going on//?</p>
