Note that there are some explanatory texts on larger screens.

plurals
  1. POEditText keeps returning null?
    primarykey
    data
    text
    <pre><code>public class Input extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EditText mEditText1 = (EditText)findViewById(R.id.number1i); String val1 = mEditText1.getText().toString(); EditText mEditText2 = (EditText)findViewById(R.id.number2i); String val2 = mEditText2.getText().toString(); double dVal1 = Double.parseDouble(val1); double dVal2 = Double.parseDouble(val2); } } </code></pre> <p>This is my 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" android:background="@drawable/background"&gt; &lt;EditText android:id="@+id/number1i" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="Enter your first value" android:inputType="numberDecimal" /&gt; &lt;EditText android:id="@+id/number2i" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="Enter your second value" android:inputType="numberDecimal" /&gt; &lt;TextView android:id="@+id/output" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="22sp" /&gt; &lt;Button android:id="@+id/add_marker" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Add value" android:onClick="userInput1" android:textSize="22sp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The error:</p> <pre><code>12-05 08:57:17.113: E/AndroidRuntime(8420): Caused by: java.lang.NullPointerException 12-05 08:57:17.113: E/AndroidRuntime(8420): at com.example.whatever.input.onCreate(input.java:23) </code></pre> <p>Line 23 is</p> <pre><code>String val1 = mEditText1.getText().toString(); </code></pre> <p>Any help please?</p> <p>I would presume because the value could be empty?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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