无法在模拟器中运行

时间:2014-08-08 03:54:28

标签: android android-emulator

我是一个新的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);
    }
}

无法在模拟器中运行。

1 个答案:

答案 0 :(得分:4)

你错过了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);