Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NumberFormatException is there a better way around this issure?
    text
    copied!<p>Here is my Java file for my app that I am working on. The in logcat it is saying there is an error in the initvar() method in this line "length1et = (EditText) findViewById(R.id.etlength1);" I know this is because there is not a variable in the edittext box and I have had this problem before and just put 0's there to start out. Is there a simple command to have nothing there and it will just understand to automatically put in a 0 for the value or is the only way to write some code to treat it as a zero? Below the java code is the xml if that is necessary. In a previous app I have just had it read the edittext box and if nothing is there, set the value to 0 before it does anything else. For the record I know I don't have a button to call the calculate() method I just haven't put that in yet.</p> <pre><code>package com.example.constructioncalculator; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class Paint extends Activity { int numwin, numdoor; double areadoor, areawin, lengthft, lengthin, widthft, widthin, heightft, heightin, areawall, areaceil, paintcon, paintneeded; EditText length1et, length2et, width1et, width2et, height1et, height2et, paintconet, paintneededet; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.paintdisp); initvar(); calculate(); output(); } private void initvar() { // TODO Auto-generated method stub numwin = 0; numdoor = 0; areawin = 20; areadoor = 19.5; lengthft = 0; lengthin = 0; widthft = 0; widthin = 0; heightft = 0; heightin = 0; areawall = 0; areaceil = 0; paintcon = 0; paintneeded = 0; length1et = (EditText) findViewById(R.id.etlength1); length2et = (EditText) findViewById(R.id.etlength2); width1et = (EditText) findViewById(R.id.etwidth1); width2et = (EditText) findViewById(R.id.etwidth2); height1et = (EditText) findViewById(R.id.etheight1); height2et = (EditText) findViewById(R.id.etheight2); paintconet = (EditText) findViewById(R.id.etpaintcon); paintneededet = (EditText) findViewById(R.id.etpaintneeded); } private void calculate() { // TODO Auto-generated method stub lengthft = Double.parseDouble(length1et.getText().toString()); lengthin = Double.parseDouble(length2et.getText().toString()); widthft = Double.parseDouble(width1et.getText().toString()); widthin = Double.parseDouble(width2et.getText().toString()); heightft = Double.parseDouble(height1et.getText().toString()); heightin = Double.parseDouble(height2et.getText().toString()); paintcon = Double.parseDouble(paintconet.getText().toString()); areaceil = (lengthft + lengthin / 12) * (widthft + widthin / 12); areawall = areaceil * (heightft + heightin / 12) - (numwin * areawin) - (numdoor * areadoor); paintneeded = (areawall / paintcon) * 1.1; } private void output() { // TODO Auto-generated method stub paintneededet.setText(String.valueOf(paintneeded)); } } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**</strong>*Here is my xml file...</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/TextView04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Paint Coverage Estimator" android:textSize="30dp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:text="@string/paintinst" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/tvlength" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Length" android:textSize="20dp" /&gt; &lt;TextView android:id="@+id/tvwidth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Width" android:textSize="20dp" /&gt; &lt;TextView android:id="@+id/tvheight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Height" android:textSize="20dp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;EditText android:id="@+id/etlength1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="feet" android:text="1" android:textSize="10dp" /&gt; &lt;EditText android:id="@+id/etlength2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="inches" android:text="1" android:textSize="10dp" /&gt; &lt;EditText android:id="@+id/etwidth1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="feet" android:text="1" android:textSize="10dp" /&gt; &lt;EditText android:id="@+id/etwidth2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="inches" android:text="1" android:textSize="10dp" /&gt; &lt;EditText android:id="@+id/etheight1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="feet" android:text="1" android:textSize="10dp" /&gt; &lt;EditText android:id="@+id/etheight2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:hint="inches" android:text="1" android:textSize="10dp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="approx paint coverage (ft^2)?" /&gt; &lt;EditText android:id="@+id/etpaintcon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="300" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Paint needed of your buckets" /&gt; &lt;EditText android:id="@+id/etpaintneeded" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload