title: How to stop program crashing when user does not enter a value?
body: <p>So basically I have a problem. When the user presses the calculate button (I'm making a calculator) without entering a value the app crashes. I want it to display a message instead but I don't know how. (updated)</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.waist2height); {
          //h is cm edittext 
          final EditText h = (EditText)findViewById(R.id.editText2);
          final EditText w = (EditText)findViewById(R.id.editText3);
  
          final EditText r = (EditText)findViewById(R.id.textView4);
  
      });
  
          calculate.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
  
              float height=0;
              float weight=0;
              float result=0;
  
  
  
              result = (float) (( weight / height ) + 0.005) ;
  
              if ((h.getText().toString()).equals(""))
                  {
                     Toast.makeText(getApplicationContext(),"Please enter your height", Toast.LENGTH_SHORT).show();
                     float height = Float.parseFloat(h.getText().toString());
                  }
                  if ((w.getText().toString()).equals(""))
                  {
                     Toast.makeText(getApplicationContext(),"Please enter your weight", Toast.LENGTH_SHORT).show();
                     float weight = Float.parseFloat(w.getText().toString());
                  }
  
  
              r.setText(String.valueOf(result));
              }
  </code></pre>
  
  <p>the code below is where i have the problem </p>
  
  <pre><code>if ((h.getText().toString()).equals(""))
                  {
                     Toast.makeText(getApplicationContext(),"Please enter your height", Toast.LENGTH_SHORT).show();
                     float height = Float.parseFloat(h.getText().toString());
                  }
                  if ((w.getText().toString()).equals(""))
                  {
                     Toast.makeText(getApplicationContext(),"Please enter your weight", Toast.LENGTH_SHORT).show();
                     float weight = Float.parseFloat(w.getText().toString());
                  }
  </code></pre>
  
  <p>This is the best I can come up with but it doesn't work.</p>
  
  <p>Here is the LogCat (Updated)</p>
  
  <pre><code>    09-20 18:50:38.509: E/AndroidRuntime(29769): FATAL EXCEPTION: main
  09-20 18:50:38.509: E/AndroidRuntime(29769): Process: com.NovaPlex.personalfitnessfree, PID: 29769
  09-20 18:50:38.509: E/AndroidRuntime(29769): java.lang.NumberFormatException: Invalid float: ""
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at java.lang.StringToReal.parseFloat(StringToReal.java:308)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at java.lang.Float.parseFloat(Float.java:306)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at com.NovaPlex.personalfitnessfree.WH$2.onClick(WH.java:80)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.view.View.performClick(View.java:4780)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.view.View$PerformClick.run(View.java:19866)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.os.Handler.handleCallback(Handler.java:739)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.os.Handler.dispatchMessage(Handler.java:95)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.os.Looper.loop(Looper.java:135)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at android.app.ActivityThread.main(ActivityThread.java:5254)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at java.lang.reflect.Method.invoke(Native Method)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at java.lang.reflect.Method.invoke(Method.java:372)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  09-20 18:50:38.509: E/AndroidRuntime(29769):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>