i am trying to create a simple android app using eclipse and android sdk (java) i have a EditText box with a few restrictions but it crashes when the EditText box is empty i have tried so many ways on checking the EditText if its empty but it just does want to work.. my code is below why does it always crash when the box is empty it should be simple no?
buttonHash.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
switch(v.getId()){
case R.id.hash_button:
TextView msg = (TextView)findViewById(R.id.tell);
info = (EditText)findViewById(R.id.entry);
anss = info.getText().toString();
//String ans = Double.toString(res);
double result = Double.parseDouble(anss);
if (res == result){
msg.setText("Correct");
}else
if (res != result){
msg.setText("Incorrect");
}else
if (info.getText().toString().equals("")){
msg.setText("Empty!");
}
}
}
});
You can use this code to solve your problem.
Thats it.. Try this …it will works.