Saturday, 14 September 2013

My App crashes when I entered nothing on edittext. What's missing in code?

My App crashes when I entered nothing on edittext. What's missing in code?

I have a problem here. I have here 2 edittext. One for amount and one for
password. My app works like a charm except when I entered NONE on the
edittexts, IT CRASHES (Unfortunately stop). Am I missing any code on my
activity? Please help. Here's my code.
public class MainActivity extends Activity {
Button REDIRECT;
private EditText txtbox1,txtbox2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
REDIRECT = (Button) findViewById(R.id.button1);
txtbox1= (EditText) findViewById(R.id.editText1);
txtbox2= (EditText) findViewById(R.id.editText2);
REDIRECT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int Amount = Integer.parseInt(txtbox1.getText().toString());
String Password = txtbox2.getText().toString();
if(Amount<=50&&Amount>=1 & Password.equals("TUBOL"))
{
final Intent i = new Intent(MainActivity.this,
Redirect.class);
startActivity(i);
}
else
{
Toast.makeText(MainActivity.this, "INVALID",
Toast.LENGTH_LONG).show();
}
}
});
}

No comments:

Post a Comment