您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

尝试对空对象引用调用虚拟方法“android.view.Window$Callback android.view.Window.getCallback()”

尝试对空对象引用调用虚拟方法“android.view.Window$Callback android.view.Window.getCallback()”

一个Activity没有完全初始化并准备查找的意见后才setContentView(...)调用onCreate()

仅声明如下字段:

private EditText usernameField, passwordField;
private TextView error;
private ProgressBar progress;

然后在中分配值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);
}

可能不是问题的一部分,而是作为额外的建议在后台线程上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);
其他 2022/1/1 18:20:42 有379人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶