lalala
lalala

Reputation: 11

cannot run in emulator

I am a new android developer and I don't know what is the problem.Please help.

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);
    }
}

It cannot run in emulator.

Upvotes: 1

Views: 81

Answers (1)

Aniruddha
Aniruddha

Reputation: 4487

You're missing setContentView(R.layout.your_layout)

Add the above line before studentid = (EditText) findViewById(R.id.studentid);

It should look like this

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

Upvotes: 4

Related Questions