title: Cannot call custom draw method from another class in Android
body: <p>its my first time to ask a question here. I have this problem with my android app.
  I would like to create different draw methods inside my custom view class. There are three buttons corresponding to 3 different shapes. When a button is pressed it will draw its shape. But the app crashes when I try to call the custom draw from the MainActivity for me to test it.</p>
  
  <p>MainActivity</p>
  
  <pre><code>import com.example.shapes.view.ShapesView;
  
  public class MainActivity extends Activity {
  
  ShapesView shapesview;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      shapesview = (ShapesView) findViewById(R.id.ShapesViewID);
      shapesview.DrawRectangle();
  }
  </code></pre>
  
  <p>ShapesView</p>
  
  <pre><code>public class ShapesView extends View{
  
  Canvas canvas;
  
  public ShapesView(Context context, AttributeSet attrs) {
      super(context, attrs);
      // TODO Auto-generated constructor stub
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      // TODO Auto-generated method stub
      super.onDraw(canvas);
      this.canvas = canvas;
  }
  
  public void DrawRectangle() {
      Paint mypaint = new Paint();
      mypaint.setColor(Color.BLUE);
      canvas.drawRect(30, 30, 200, 200, mypaint);
  }
  }
  </code></pre>
  
  <p>My XML layout file</p>
  
  <p><code>&lt;com.example.shapes.view.ShapesView 
          android:id="@+id/ShapesViewID"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;</code></p>
  
  <pre><code>&lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" /&gt;`
  </code></pre>
  
  <p>Please do help! Thank you very much!</p>