尝试在空对象引用上调用虚拟方法‘android.view.Window$回调-android.view.Window.getCallback()’当我SplashActivity打开LoginActivity我的应用程序崩溃了。以下是我的SplashActivity.java:package com.example.android.appName;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;
import java.util.Timer;import java.util.TimerTask;public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}, 1500);
}}我的LoginActivity.java:package com.example.android.appName;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;
import android.widget.EditText;import android.widget.ProgressBar;import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
private EditText usernameField = (EditText)findViewById(R.id.username),
passwordField = (EditText)findViewById(R.id.password);
private TextView error = (TextView)findViewById(R.id.error);
private ProgressBar progress = (ProgressBar)findViewById(R.id.progress);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.login_menu, menu);
return true;
}
2 回答
莫回无
TA贡献1865条经验 获得超7个赞
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
new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); }}, 1500);
饮歌长啸
TA贡献1951条经验 获得超3个赞
ContentView
setContentView(R.layout.xml_file_name);
onCreate
View
onCreate
添加回答
举报
0/150
提交
取消