Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems from Editable (EditText) to Integers
    text
    copied!<p>I am having problems getting the integer values for a simple math program out of the edittext boxes. I can get a string out of it but when I try to convert it to a integer it crashes. I have tried:</p> <pre><code>int a = Intger.parseInt(X2.getText().toString()); </code></pre> <p>and it still crashes. Any idea's would be greatly appreciated. Here is source code.</p> <pre><code>package siu.edu.cs215; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.*; public class Quadratic extends Activity { private TextView answer; private EditText X2, X, K; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.quad); Button1 = (Button)findViewById(R.id.quad); Button2 = (Button)findViewById(R.id.backwards); answer = (TextView)findViewById(R.id.B1); X2 = (EditText)findViewById(R.id.xsquared); X = (EditText)findViewById(R.id.xcoeff); K = (EditText)findViewById(R.id.kconst); } public Button Button1 = null; public Button Button2 = null; public void QA (View view){ //double sol1=0.0, sol2=0.0, disc=0.0; int a = Integer.parseInt(X2.getText().toString()); //int b = Integer.getInteger(X.getText().toString()); //int c = Integer.getInteger(K.getText().toString()); //disc = Math.pow(b, 2) - 4.0*a*c; //sol1 = (-b + Math.sqrt(disc)) / (2.0 * a); //sol2 = (-b - Math.sqrt(disc)) / (2.0 * a); answer.setText(a); }; public void BACK (View view){ Intent i = new Intent(this, ExtraCreditActivity.class); startActivity(i); } } </code></pre> <p>Here is the xml file </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &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;TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" &gt; &lt;TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight=".6" &gt; &lt;/TableRow&gt; &lt;TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" &gt; &lt;EditText android:id="@+id/xsquared" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_weight="1" android:inputType="number" /&gt; &lt;TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="0dp" android:layout_weight="1" android:gravity="center" android:text="X^2 +" android:textSize="20dp" /&gt; &lt;EditText android:id="@+id/xcoeff" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" /&gt; &lt;TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_weight="1" android:gravity="center" android:text="X + " android:textSize="20dp" /&gt; &lt;EditText android:id="@+id/kconst" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:layout_weight="1" android:inputType="number" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;/TableRow&gt; &lt;TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1.2" &gt; &lt;Button android:id="@+id/quad" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="QA" android:text="Quadratic" /&gt; &lt;/TableRow&gt; &lt;TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight=".8" &gt; &lt;TextView android:id="@+id/B1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="2pt" android:text="@string/app_name" /&gt; &lt;/TableRow&gt; &lt;TableRow android:id="@+id/tableRow5" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/backwards" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Back" android:onClick="BACK" /&gt; &lt;/TableRow&gt; &lt;/TableLayout&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