慕工程0101907
2019-03-22 19:15:46
我使用 eclipse 和 android sdk (java) 創(chuàng)建了一個簡單的程序,在 EditText box 中有一些限制,但是當(dāng) EditText box 是空的時候程序就奔潰了。我用了很多方法來檢查 EditText 是否為空,但是它還是不能運行的。為什么當(dāng)box是空的時候程序奔潰?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!");
}
}
}
});
添加回答
舉報
0/150
提交
取消