title: How to parse a double from EditText to TextView? (Android)
body: <p>I'm realy beginning to learn Java.
  When I run this code everything works fine till I leave my EditText boxes in the from empty and hit the run button. Then I get: </p>
  
  <pre><code>ERROR/AndroidRuntime(866): FATAL EXCEPTION: main
  ERROR/AndroidRuntime(866): java.lang.NumberFormatException: 
  ERROR/AndroidRuntime(866):     at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
  </code></pre>
  
  <p>I guess when I try to parse a Double from string it doesn't get any value and creates an error.
  I was wondering how to avoid this error and give some kind of a value to the variable so it is never empty? Thanks for all the help!</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Button;
  import android.view.View;
  import android.view.View.OnClickListener;
  
  public class Main extends Activity {
  
      private EditText noKids;
      private EditText noGumballs;
      private TextView noSum;
      private Button b;
      private Button br;
      double etKids = 0;
      double etGumballs = 0;
      private double tvSumIn = 0.00;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          initControls();
      }
  
  
      private void initControls() {
          noKids = (EditText) findViewById(R.id.xetKids);
          noGumballs = (EditText) findViewById(R.id.xetGumballs);
          noSum = (TextView) findViewById(R.id.tvSum);
  
  
          br = (Button) findViewById(R.id.xbtnReset);
          br.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  reset();
                  br.setVisibility(View.INVISIBLE);
              }
  
              private void reset() {
                  noKids.setText("");
                  noGumballs.setText("");
                  noSum.setText("");
  
              }
  
          });
  
          b = (Button) findViewById(R.id.xbtnCalculate);
          b.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {               
                  calculate();
                  br.setVisibility(View.VISIBLE);
                  }
  
          private void calculate() {
  
              etKids = Double.parseDouble(noKids.getText().toString());
              etGumballs = Double.parseDouble(noGumballs.getText().toString());
              tvSumIn = etGumballs / etKids; 
              String thisIsIt = new Double(tvSumIn).toString();
  
              if(tvSumIn &lt; 2){
                  noSum.setText(thisIsIt + " This is it ");
              }else{
                  noSum.setText("This is else");
              }
  
          }
  
          });
  
  
  
          }
      }
  </code></pre>
  
  <p>This is my main.xml file
  and I'm guessing there's nothing special to put into manifest.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="How many kids have you got?"&gt;&lt;/TextView&gt;
      &lt;EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:id="@+id/xetKids"&gt;
          &lt;requestFocus&gt;&lt;/requestFocus&gt;
      &lt;/EditText&gt;
      &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="How many gumballs have you got?"&gt;&lt;/TextView&gt;
      &lt;EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:id="@+id/xetGumballs"&gt;&lt;/EditText&gt;
      &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Calculate" android:id="@+id/xbtnCalculate"&gt;&lt;/Button&gt;
      &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvSum"&gt;&lt;/TextView&gt;
      &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/xbtnReset" android:text="Reset" android:onClick="selfDestruct" android:visibility="invisible"&gt;&lt;/Button&gt;
  &lt;/LinearLayout&gt;
  </code></pre>