My application crash if the user have empty EditText.
I've tried several solution found on this board, but none of them worked for me. Anyone have any idea how to fix this? The problem is in the "else if".
Thanks.
Code:
TextView textA, textB, textX, textEqual, textIncorrect;
Button buttonGo;
EditText editA;
Random rand = new Random();
int textAA = rand.nextInt(10) + 1;
int textBB = rand.nextInt(10) + 1;
int Asnwer;
private int andB;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textA = (TextView)findViewById(R.id.textA);
textB = (TextView)findViewById(R.id.textB);
textX = (TextView)findViewById(R.id.textX);
textEqual = (TextView)findViewById(R.id.textEqual);
textIncorrect = (TextView)findViewById(R.id.textIncorrect);
editA = (EditText)findViewById(R.id.editA);
buttonGo = (Button)findViewById(R.id.buttonGo);
//Set
textIncorrect.setText("");
editA.setText(String.valueOf(""));
textA.setText(String.valueOf(textAA));
textB.setText(String.valueOf(textBB));
buttonGo.setOnClickListener(this);
}
@Override
public void onClick(View src) {
switch(src.getId()) {
case R.id.buttonGo:
andB = this.textBB * this.textAA;
if(andB == Integer.parseInt(editA.getText().toString())) {
editA.setText("");
this.textIncorrect.setTextColor(Color.BLUE);
this.textIncorrect.setText("CORECCT: " + this.textBB + " x " + this.textAA + " = " + andB);
this.textAA = rand.nextInt(50)+1;
this.textBB = rand.nextInt(50)+1;
textA.setText(String.valueOf(this.textAA));
textB.setText(String.valueOf(this.textBB));
}else if(Integer.parseInt(editA.getText().toString()) < 0){
this.textIncorrect.setText("Error!");
}else{
this.textIncorrect.setTextColor(Color.RED);
this.textIncorrect.setText("INCORECCT!");
}
}
}
}
I've tried several solution found on this board, but none of them worked for me. Anyone have any idea how to fix this? The problem is in the "else if".
Thanks.