我想知道你將如何去輸出其中的兩個文本框拖住NumberFormatException異常。NumberFormatException的2個文本框的Java
try
{
num1Convert = Integer.parseInt(num1Str);
num2Convert = Integer.parseInt(num2Str);
sumValue = num1Convert + num2Convert;
sumLabel.setText(sumText + Integer.toString(sumValue));
}
catch(NumberFormatException nfe)
{
errorLabel.setText((HERE IS WHERE I NEED TO PUT CODE TO SAY WHICH TEXTFIELD IT IS" must be an integer");
num1.requestFocus();
}
我的程序會比較兩個數字,然後返回相加的數字的價值,但我需要這兩個文本域的都扔回去異常輸出,但我不知道如何做到這一點。我在代碼中寫過需要輸出它的地方。
如何對兩個單獨的try catch塊?或者這太明顯瞭解決方案? –
的可能的複製[什麼是NumberFormatException異常,我該如何解決?(http://stackoverflow.com/questions/39849984/what-is-a-numberformatexception-and-how-can-i-fix-it) – xenteros