Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
An Activity
is not fully initialized and ready to look up views until after setContentView(...)
is called in onCreate()
.
Only declare the fields like the following:
private EditText usernameField, passwordField;
private TextView error;
private ProgressBar progress;
and then assign the values in onCreate
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
usernameField = (EditText)findViewById(R.id.username);
passwordField = (EditText)findViewById(R.id.password);
error = (TextView)findViewById(R.id.error);
progress = (ProgressBar)findViewById(R.id.progress);
}
Might not be part of the problem but as an extra bit of advice a Timer
runs the TimerTask
on a background thread and that should be avoided in this case. Replace the Timer
with a Handler
instead to run it on the UI thread.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}, 1500);