I'm trying to create a generic login screen for Android. I'd like the program to check if the username and password (currently hardcoded) is listed. If the account is listed, you will be taken to a new screen called menuTest
. I have the basic login working (without activity or intents). But when I try to add the intents, I get an error. How can I fix this? Below is my sample code.
Below are a few links containing screenshots of crash and logcat (edit: links are dead).
http://i.stack.imgur.com/ve7OL.png
http://i.stack.imgur.com/KLeQa.png
Thanks.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends Activity {
// Declare our Views, so we can access them later
private EditText etUsername;
private EditText etPassword;
private Button btnLogin;
private Button btnCancel;
private TextView lblResult;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set Activity Layout
setContentView(R.layout.login);
// Get the EditText and Button References
etUsername = (EditText)findViewById(R.id.username);
etPassword = (EditText)findViewById(R.id.password);
btnLogin = (Button)findViewById(R.id.login_enter);
btnCancel = (Button)findViewById(R.id.login_cancel);
lblResult = (TextView)findViewById(R.id.result);
// Set Click Listener
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Check Login
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if(username.equalsIgnoreCase("USER") && password.equals("132465")){
//lblResult.setText("Login successful");
Intent loginIntent = new Intent(this, menuTest.class);
startActivity(loginIntent);
}
else {
lblResult.setText("Login Failed");
}
}
});
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Close the application
finish();
}
});
}
}