title: Android Null Pointer Exception on drawColor
body: <p>I have some problem, here in my code I am trying to draw canvas on frameLayout but I am getting Null Object Reference exception. By the way when I changed Color.BLACK nothing change only show black rectangle and give error.
  I use android studio 2.1 and genymotion android emulator 6.0 Marshmallow</p>
  
  <p><strong>Error</strong> is like that : </p>
  
  <pre><code>Fatal Exception:main
  Process:com.example.myApp
  java.lang.NullPointerException : Attempt to invoke virtual method "void android.graphics.Canvas.rawColor(int)" on a null object reference
  </code></pre>
  
  <hr>
  
  <pre><code>public class MyCanvas extends SurfaceView implements SurfaceHolder.Callback{
  
      private boolean mRun= false;
      private final SurfaceHolder mSurfaceHolder;
      private final Object mRunLock = new Object();
  
      public MyCanvas(Context context, AttributeSet attrs){
  
          super(context,attrs);
          this.setWillNotDraw(false);
          mSurfaceHolder = getHolder();
          mSurfaceHolder.AddCallback(this);   
      }
  
      public synchronized void run(){
  
          if(mRun){
  
              Canvas c = null;
              try{
  
                  c = mSurfaceHolder.lockCanvas();
                  synchronized (mSurfaceHolder){
                      synchronized(mRunLock){
                          if(mRun) doDraw(c);
                      }
  
                  }
  
              }finally
                  if(c != null)
                  { mSurfaceHolder.unlockCanvasandPost(c);    }
  
          }   
  
  
      }
  
  
      private void onDraw(Canvas canvas){
         canvas.drawColor(Color.YELLOW);
      }
  }
  </code></pre>
  
  <p>my activity layout code is here.</p>
  
  <pre><code>&lt;view class="com.example.myapp.MyCanvas"
      android:layout_width="200dp"
      android:layout_height="200dp"
      android:lid="@+id/mycanvas"
  /&gt;
  </code></pre>
  
  <p>my activity class is here</p>
  
  <pre><code>MyCanvas myCanvas = (MyCanvas)findViewById(R.id.mycanvas);
  myCanvas.run();
  </code></pre>