Android: onClick unfortunately stopped
<p>I want to write a easy image editor on android. But there is a problem. All are correct when I run it on the emulator, until press the button.  "Unfortunately, .....stop.." showed up on the screen and program was forced to shut down. But I really know where is wrong. Please help me to figure it out. Thank you very much.</p>

<p>here is my program code.</p>

<pre><code>btn1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            draw(drawAction.effect_gray);
            }
        });

    btn2.setOnClickListener(new OnClickListener() {  
         public void onClick(View arg0) {
             draw(drawAction.effect_negative);
            }
        });
    }

@Override
protected void onResume() {
    super.onResume();

}

enum drawAction {
    effect_gray, effect_negative;
}

void draw(drawAction action) {
    Canvas canvas = null;

    switch (action) {
    case effect_gray:
         gray(canvas);
        break;
    case effect_negative:
        negative(canvas);
         break;
}
        }
void gray(Canvas canvas) {
    Bitmap vBitmap2 = BitmapFactory.decodeResource( this.getResources()
            , R.drawable.images);

    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(vBitmap2, 0, 0, paint);

 img1.setImageBitmap(vBitmap2);
}

    void negative(Canvas canvas) {
     Bitmap vBitmap2 = BitmapFactory.decodeResource( this.getResources()
                , R.drawable.images);
  Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);    
  ColorMatrix cm = new ColorMatrix(new float[] {  
    -1f,  0f,  0f, 0f, 255f,  
     0f, -1f,  0f, 0f, 255f,  
     0f,  0f, -1f, 0f, 255f,  
     0f,  0f,  0f, 1f,   0f});  
  paint.setColorFilter(new ColorMatrixColorFilter(cm));  
  canvas.drawBitmap(vBitmap2, 0, 0, paint);  

  img1.setImageBitmap(vBitmap2);
}
}



12-16 16:32:11.741: E/AndroidRuntime(597): FATAL EXCEPTION: main
12-16 16:32:11.741: E/AndroidRuntime(597): java.lang.NullPointerException
12-16 16:32:11.741: E/AndroidRuntime(597):  at com.example.a.Aa.gray(Aa.java:81)
12-16 16:32:11.741: E/AndroidRuntime(597):  at com.example.a.Aa.draw(Aa.java:64)
12-16 16:32:11.741: E/AndroidRuntime(597):  at com.example.a.Aa$1.onClick(Aa.java:37)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.view.View.performClick(View.java:3480)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.view.View$PerformClick.run(View.java:13983)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.os.Handler.handleCallback(Handler.java:605)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.os.Looper.loop(Looper.java:137)
12-16 16:32:11.741: E/AndroidRuntime(597):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-16 16:32:11.741: E/AndroidRuntime(597):  at java.lang.reflect.Method.invokeNative(Native Method)
12-16 16:32:11.741: E/AndroidRuntime(597):  at java.lang.reflect.Method.invoke(Method.java:511)
12-16 16:32:11.741: E/AndroidRuntime(597):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-16 16:32:11.741: E/AndroidRuntime(597):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-16 16:32:11.741: E/AndroidRuntime(597):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>
