我是一名新的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/

10-14 12:23