title: App crash on android:onClick from XML
body: <p>I'm using a button to perform a calculation from an activity (not main) and my app crashes at pressing the button.</p>
  
  <p>My XML is:</p>
  
  <pre><code>&lt;Button
      android:id="@+id/calculate"
      android:onClick="calculateEngland"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/button"
      android:layout_margin="10dp"/&gt;
  </code></pre>
  
  <p>And the calculateEngland method is:</p>
  
  <p>public class England_Activity extends ActionBarActivity {</p>
  
  <pre><code>double x, y;
  EditText propValue, stampDuty;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_england);
  
      AdView mAdView = (AdView) findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder().build();
      mAdView.loadAd(adRequest);
  }
  
  public void calculateEngland(View view)
  {
      EditText propValue = (EditText) findViewById(R.id.propValue);
      EditText stampDuty = (EditText) findViewById(R.id.stampDuty);
      hideSoftKeyboard();
  
      x=Double.parseDouble(propValue.getText().toString());
  
      if (x &lt;= 125000 ) {
          y = 0.0;
      } else if (x &lt;= 250000) {
          y = (x - 125000) * 0.02;
      } else if (x &lt;= 925000) {
          y = (125000 * 0.02) + ((x - 250000) * 0.05);
      } else if (x &lt;= 1500000) {
          y = (125000 * 0.02) + (675000 * 0.05) + ((x - 925000) * 0.1);
      } else if (x &gt; 150000) {
          y = (125000 * 0.02) + (675000 * 0.05) + (575000 * 0.1) + ((x - 1500000) * 0.12);
      }
  
      stampDuty.setText(Double.toString(y));
  }
  
  private void hideSoftKeyboard(){
      if(getCurrentFocus()!=null &amp;&amp; getCurrentFocus() instanceof EditText){
          InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(propValue.getWindowToken(), 0);
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_england, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The logcat shows:</p>
  
  <pre><code>Process: uk.xeeleestudios.stampdutycalculator, PID: 3461
  java.lang.IllegalStateException: Could not execute method of the activity
      at android.view.View$1.onClick(View.java:4253)
      at android.view.View.performClick(View.java:5197)
      at android.view.View$PerformClick.run(View.java:20926)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:145)
      at android.app.ActivityThread.main(ActivityThread.java:5942)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
   Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at android.view.View$1.onClick(View.java:4248)
      at android.view.View.performClick(View.java:5197)
      at android.view.View$PerformClick.run(View.java:20926)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:145)
      at android.app.ActivityThread.main(ActivityThread.java:5942)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.widget.EditText.getWindowToken()' on a null object reference
      at uk.xeeleestudios.stampdutycalculator.England_Activity.hideSoftKeyboard(England_Activity.java:57)
      at uk.xeeleestudios.stampdutycalculator.England_Activity.calculateEngland(England_Activity.java:35)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at android.view.View$1.onClick(View.java:4248)
      at android.view.View.performClick(View.java:5197)
      at android.view.View$PerformClick.run(View.java:20926)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:145)
      at android.app.ActivityThread.main(ActivityThread.java:5942)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
  </code></pre>