我想在用戶點擊「Bintro」按鈕並且EditTexts爲空時向用戶顯示一條消息。Catch不執行Toast
我有下面的代碼:
Bintro.setOnClickListener(new View.OnClickListener() {
String eva;
double por, not;
@Override
public void onClick(View v){
try{
eva = edEva.getText().toString();
por = Double.parseDouble(edPor.getText().toString());
not = Double.parseDouble(edNot.getText().toString());
}
catch (Exception e){
Toast.makeText(getApplicationContext(), "Faltan datos por introducir", Toast.LENGTH_LONG);
return;
}
//The code continues down here but it's irrelevant to solve the question.
我的問題是,當我按一下按鈕,就沒有充滿的EditText的「抓」不執行吐司消息,但是,但是,它返回該應用會從onClick方法中退出。當它們被填滿時,應用程序將完美地執行「catch」下的代碼。
希望你能幫助我的代碼或以另一種方式來做到這一點。謝謝。
你有沒有* *顯示敬酒消息?如果您將該行移到catch塊外面會發生什麼? (提示:問題與try/catch沒有任何關係) –
是的。我知道是什麼問題。只是忘了「.show()」。我的(非常)不好! – JCoder