title: Android - Getting a null pointer exception when calling custom View method
body: <p>I'm new to android and i'm trying to call a method that moves a circle drawn by a custom view using canvas up by 10 pixels. When i try to call said method, i get a null pointer exception and i can't figure out why. Here is what i have.</p>
  
  <p>Main Activity</p>
  
  <pre><code>public class CustomView extends Activity {
  XView xv;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_customview);
  }
  
  public void moveUp(View view){
      xv.setY(view);
  }
  
  }
  </code></pre>
  
  <p>The Custom View</p>
  
  <pre><code>public class XView extends View implements View.OnClickListener{
  
  private Paint mPaint = new Paint();
  int oX = 200;
  int oY = 200;
  
  
  public XView(Context context, AttributeSet attrs){
      super(context, attrs);
      //setOnClickListener(this);
  }
  
  
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      mPaint.setStyle(Paint.Style.FILL);
      mPaint.setColor(Color.MAGENTA);
  
      canvas.drawColor(Color.WHITE);
      canvas.drawCircle(oX, oY, 50, mPaint);
  }
  public void onClick(View view){
      oX=oX+10;
      view.postInvalidate();
  }
  
  
  public void setY(View view)
  {
      oY=oY+10;
      view.postInvalidate();
  }
  }
  </code></pre>
  
  <p>The XML for the main activity</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".customview"
  android:orientation="vertical"&gt;
  
  &lt;com.mycompany.customview.XView
      android:layout_width="wrap_content"
      android:layout_height="200dp" /&gt;
  
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:layout_alignParentTop="true"
          android:layout_alignLeft="@+id/button2"
          android:layout_alignStart="@+id/button2"
          android:onClick="moveUp"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="right"
          android:layout_alignTop="@+id/button2"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@+id/button"
          android:layout_centerHorizontal="true"
          android:id="@+id/button2" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:layout_centerVertical="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"
          android:id="@+id/button" /&gt;
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:id="@+id/button5"
          android:layout_alignParentBottom="true"
          android:layout_alignLeft="@+id/button2"
          android:layout_alignStart="@+id/button2" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks</p>