一个
Activity没有完全初始化并准备查找的意见后才
setContentView(...)被调用
onCreate()。
仅声明如下字段:
private EditText usernameField, passwordField;private TextView error;private ProgressBar progress;
然后在中分配值
onCreate:
@Overrideprotected 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);}可能不是问题的一部分,而是作为额外的建议在后台线程上
Timer运行,
TimerTask在这种情况下应避免使用。将其替换为
Timer,以
Handler在UI线程上运行它。
new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); }}, 1500);


