I'm getting the following error randomly, that is, it gives error a few times and others do not:
Caused by: java.lang.NullPointerException
at pt.cartuxa.Login.onCreate(Login.java:62)
My 62 line is as follows:
password.setImeActionLabel(getString(R.string.keyboard_enter), KeyEvent.KEYCODE_ENTER);
Complete code:
public class Login extends Activity {
EditText username, password;
Editable user_input, pass_input;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// SETTERS
username = (EditText) findViewById(R.id.txt_login_user);
password = (EditText) findViewById(R.id.txt_login_pass);
// VIEW
setContentView(R.layout.login_layout);
// VIEW CONFIGS
password.setImeActionLabel(getString(R.string.keyboard_enter), KeyEvent.KEYCODE_ENTER);
}
}
I created line 62 to change the text of the Enter button to "Login" but it happens that when I run the application, sometimes it initializes correctly and sometimes blocks on that line giving the error described above.
How can I prevent this error?