title: Converting simple image to greyscale
body: <p>I am trying to convert a normal colored image to greyscale image.Code is really simple but don't know why I am getting error.I am just changing color value pixel by pixel and then storing it in the new bitmap.Error is coming when I am trying to set pixels to the new bitmap.</p>
  
  <pre><code> Bitmap c=BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/1.jpg");
  
      int width=c.getWidth();
      int height=c.getHeight();
      int A,B,R,G;
      int pixel;
  
  
  
  
      for(int x = 0; x &lt; width; x++) {
          for(int y = 0; y &lt; height; y++) {
              // get one pixel color
  
         //     pixel = c.getPixel(x, y);
              // retrieve color of all channels
  
    //          A = Color.alpha(c.getPixel(x, y));
              R = Color.red(c.getPixel(x, y));
              G = Color.green(c.getPixel(x, y));
              B = Color.blue(c.getPixel(x, y));
  
              // take conversion up to one single value
              R = G = B = (int)(0.299 * R + 0.587 * G + 0.114 * B);
              // set new pixel color to output bitmap
              h=String.valueOf(R);
             bmOut.isMutable();
             bmOut.setPixel(x, y, Color.argb(Color.alpha(c.getPixel(x, y)), R, G, B));
          }
      //  Toast.makeText(getApplicationContext(), h, Toast.LENGTH_SHORT).show();    
      }
  </code></pre>
  
  <p>Here's my logcat</p>
  
  <pre><code>  05-02 13:37:37.858: E/AndroidRuntime(19254): FATAL EXCEPTION: main
    05-02 13:37:37.858: E/AndroidRuntime(19254): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.otsu/com.example.otsu.MainActivity}: java.lang.NullPointerException
    05-02 13:37:37.858: E/AndroidRuntime(19254):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
    05-02 13:37:37.858: E/AndroidRuntime(19254):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.app.ActivityThread.access$1500(ActivityThread.java:135)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.os.Handler.dispatchMessage(Handler.java:99)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.os.Looper.loop(Looper.java:150)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.app.ActivityThread.main(ActivityThread.java:4389)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at java.lang.reflect.Method.invokeNative(Native Method)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at java.lang.reflect.Method.invoke(Method.java:507)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at dalvik.system.NativeStart.main(Native Method)
   05-02 13:37:37.858: E/AndroidRuntime(19254): Caused by: java.lang.NullPointerException
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at com.example.otsu.MainActivity.onCreate(MainActivity.java:58)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
   05-02 13:37:37.858: E/AndroidRuntime(19254):   ... 11 more
  </code></pre>