Error while saving bitmap to sdcard in android
<p>I have a problem that when I am going to save my bitmap image to sdcard in PNG format then code always returns an error which is described below, I don't know why? Please suggest me the right solution regarding the same.</p>

<p><strong>Error Stack:</strong></p>

<pre><code>12-28 12:50:58.765: ERROR/AndroidRuntime(16977): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.greetingApp.common/com.greetingApp.common.Greeting}: java.lang.NullPointerException
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.os.Looper.loop(Looper.java:123)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at java.lang.reflect.Method.invokeNative(Native Method)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at java.lang.reflect.Method.invoke(Method.java:521)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at dalvik.system.NativeStart.main(Native Method)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977): Caused by: java.lang.NullPointerException
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at com.greetingApp.common.Greeting.SaveData(Greeting.java:138)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at com.greetingApp.common.Greeting.onCreate(Greeting.java:78)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-28 12:50:58.765: ERROR/AndroidRuntime(16977):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>protected void SaveData() 
        {


          FrameLayout view = (FrameLayout)findViewById(R.id.frameLayout2);
          view.setDrawingCacheEnabled(true);
          view.buildDrawingCache();
          bm = view.getDrawingCache();

          OutputStream outStream = null;
           File file = new File(extStorageDirectory, "er.PNG");
           try {
            outStream = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();

            //Toast.makeText(AndroidWebImage.this, "Saved", Toast.LENGTH_LONG).show();

           } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            //Toast.makeText(AndroidWebImage.this, e.toString(), Toast.LENGTH_LONG).show();
           } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           // Toast.makeText(AndroidWebImage.this, e.toString(), Toast.LENGTH_LONG).show();

            // TODO Auto-generated method stub

        }
</code></pre>

<p>Thanks in advance</p>
