Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointerexception when checking EditText value
    primarykey
    data
    text
    <p>I get a nullpointerexception when I do this:</p> <pre><code>EditText[] answers; </code></pre> <p>//At the oncreate method I do this:this is set after the setContent() method.</p> <pre><code> answers=new EditText[6]; answers[0]=(EditText) findViewById(R.id.editText1); answers[1]=(EditText) findViewById(R.id.editText2); answers[2]=(EditText) findViewById(R.id.editText3); answers[3]=(EditText) findViewById(R.id.editText4); answers[4]=(EditText) findViewById(R.id.editText5); answers[5]=(EditText) findViewById(R.id.editText6); </code></pre> <p>In the onClickListener of the button I put this:</p> <pre><code>nextQuestion_btn.setOnClickListener(new View.OnClickListener() { for(EditText item : answers) { if(item.getText().toString().equals("")) { //nuller Exception here editTextIsEmpty=true; break; } } } </code></pre> <p>why do I get a nullpointerexception... in the if statement?</p> <p>UPDATE; I put all the EditText into an array. All the code is inside the onCreate method</p> <p>This is what I get:</p> <pre><code> 11-29 16:11:24.076: E/AndroidRuntime(616): FATAL EXCEPTION: main 11-29 16:11:24.076: E/AndroidRuntime(616): java.lang.NullPointerException 11-29 16:11:24.076: E/AndroidRuntime(616): at com.NewOrder.SetTest$1.onClick(SetTest.java:95) 11-29 16:11:24.076: E/AndroidRuntime(616): at android.view.View.performClick(View.java:2485) 11-29 16:11:24.076: E/AndroidRuntime(616): at android.view.View$PerformClick.run(View.java:9080) 11-29 16:11:24.076: E/AndroidRuntime(616): at android.os.Handler.handleCallback(Handler.java:587) 11-29 16:11:24.076: E/AndroidRuntime(616): at android.os.Handler.dispatchMessage(Handler.java:92) 11-29 16:11:24.076: E/AndroidRuntime(616): at android.os.Looper.loop(Looper.java:123) </code></pre>
    singulars
    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