Reputation: 317
public class Admin extends Activity implements OnClickListener{
EditText password;
Button enter;
private int one=1;
private int zero=0;
private String pass;
protected static String PASSWORD="1234";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.password);
password=(EditText) findViewById(R.id.editText_password);
enter=(Button) findViewById(R.id.Button_enter);
enter.setOnClickListener(this);
}
@Override
public void onBackPressed() {
setResult(zero);
super.onBackPressed();
}
@Override
public void onClick(View v) {
pass=password.getText().toString();
if(pass.matches(PASSWORD)){
setResult(one);
Admin.this.finish();
}
else
password.setText("");
}
}
When i remove the if condition then it works but with if condition it give me error:"The application Password Manager has been stoped unexpectedly".So anyone who can help me i am thanking him in advance.
Upvotes: 1
Views: 2627
Reputation: 5099
Try changing:
if(pass.matches(PASSWORD)){
...
}
into:
if(pass.equals(PASSWORD)){
...
}
Upvotes: 3