gpt4 book ai didi

android - 无法在模拟器中运行

转载 作者:行者123 更新时间:2023-11-29 16:00:09 25 4
gpt4 key购买 nike

我是一名新的 android 开发人员,我不知道问题是什么。请帮忙。

public class MainActivity extends Activity {

private EditText studentid, password;
private ImageView login, reset;

@Override
protected void onCreate(Bundle savedInstanceState) {

studentid = (EditText) findViewById(R.id.studentid);
password = (EditText) findViewById(R.id.password);

login = (ImageView) findViewById(R.id.login);

login.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
String un = studentid.getText().toString();
String pw = password.getText().toString();
String setun = "s123";
String setpw = "456";
if (un.equals(setun) && pw.equals(setpw)) {
loginsuccess();
} else {
studentid.setText("");
password.setText("");
Toast toast = Toast.makeText(v.getContext(),
"Wrong username or password...", Toast.LENGTH_LONG);
toast.show();
}
}
});
}

private void loginsuccess() {
Intent intent = new Intent(MainActivity.this, edit.class);
startActivity(intent);
}
}

它不能在模拟器中运行。

最佳答案

你缺少 setContentView(R.layout.your_layout)

studentid = (EditText) findViewById(R.id.studentid); 之前添加以上行

应该是这样的

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout); // this line is missing
studentid = (EditText) findViewById(R.id.studentid);

关于android - 无法在模拟器中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25195819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com