title: Cannot execute method for android:onClick
body: <p>I have this activity in my application wherein when a user clicks a button, it will execute <code>CameraUpdate</code> which is inside a method. Here's the code:</p>
  
  <p><strong>LocationsActivity.java</strong></p>
  
  <pre><code>public class TermLocActivity extends AppCompatActivity implements OnMapReadyCallback {
  
      GoogleMap map;
  
  
      public static final CameraPosition MoloTerminal =
              new CameraPosition.Builder().target(new LatLng(10.699160, 122.547208))
              .zoom(16)
              .bearing(300)
              .tilt(50)
              .build();
  
      public static final CameraPosition TagbakTerminal =
              new CameraPosition.Builder().target(new LatLng(10.761854, 122.577128))
                      .zoom(16)
                      .bearing(300)
                      .tilt(50)
                      .build();
  
      public static final CameraPosition CeresTerminal =
              new CameraPosition.Builder().target(new LatLng(10.758862, 122.567774))
                      .zoom(16)
                      .bearing(300)
                      .tilt(50)
                      .build();
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_term_loc);
  
          SupportMapFragment mapFragment =
                  (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
  
  
      }
  
      @Override
      public void onMapReady(GoogleMap map) {
  
          map.addMarker(new MarkerOptions().position(new LatLng(10.699160, 122.547208)).title("San Pedro Molo Terminal"));
          map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(10.699160, 122.547208), 16));
      }
  
  
      public void onGoToMoloTerm(View v) {
  
          map.animateCamera(CameraUpdateFactory.newCameraPosition(MoloTerminal));
  
      }
      public void onGoToTagbakTerm(View v) {
  
          map.animateCamera(CameraUpdateFactory.newCameraPosition(TagbakTerminal));
  
      }
      public void onGoToCeresTerm(View v) {
  
          map.animateCamera(CameraUpdateFactory.newCameraPosition(CeresTerminal));
  
      }
  }
  </code></pre>
  
  <p>Here's the XML file:</p>
  
  <p><strong>activity_locations.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout 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:paddingTop="15dp"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:paddingBottom="10dp"
      tools:context="com.thesis.iwander.TermLocActivity"&gt;
  
      &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="?attr/actionBarSize"
          class="com.google.android.gms.maps.SupportMapFragment"/&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Molo Term."
          android:id="@+id/button"
          android:onClick="onGoToMoloTerm"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Ceres Term."
          android:id="@+id/button2"
          android:onClick="onGoToCeresTerm"
          android:layout_alignTop="@+id/button"
          android:layout_toRightOf="@+id/button"
          android:layout_toEndOf="@+id/button"
          android:layout_marginLeft="13dp" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Tagbak Term."
          android:id="@+id/button3"
          android:onClick="onGoToTagbakTerm"
          android:layout_alignTop="@+id/button2"
          android:layout_alignRight="@+id/map"
          android:layout_alignEnd="@+id/map" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>So whenever I test the app and click on one of the buttons, the app crashes and the logcat shows this error:</p>
  
  <pre><code>FATAL EXCEPTION: main
     Process: com.thesis.iwander, PID: 28783
     java.lang.IllegalStateException: Could not execute method for android:onClick
     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener
            .onClick(AppCompatViewInflater.java:293)
     at android.view.View.performClick(View.java:4472)
     at android.view.View$PerformClick.run(View.java:18779)
     at android.os.Handler.handleCallback(Handler.java:808)
     at android.os.Handler.dispatchMessage(Handler.java:103)
      at android.os.Looper.loop(Looper.java:193)
     at android.app.ActivityThread.main(ActivityThread.java:5333)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
     at dalvik.system.NativeStart.main(Native Method)
      Caused by: java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:515)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener
           .onClick(AppCompatViewInflater.java:288)
       at android.view.View.performClick(View.java:4472) 
        at android.view.View$PerformClick.run(View.java:18779) 
        at android.os.Handler.handleCallback(Handler.java:808) 
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:5333) 
         at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
         at dalvik.system.NativeStart.main(Native Method) 
         Caused by: java.lang.NullPointerException
            at com.thesis.iwander.TermLocActivity.onGoToCeresTerm(TermLocActivity.java:77)
           at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
           at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener
               .onClick(AppCompatViewInflater.java:288) 
          at android.view.View.performClick(View.java:4472) 
           at android.view.View$PerformClick.run(View.java:18779) 
           at android.os.Handler.handleCallback(Handler.java:808) 
            at android.os.Handler.dispatchMessage(Handler.java:103) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:5333) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
              at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>
  
  <p>I tried to find questions which are similar to mine but I couldn't find any.</p>