2017-04-14 32 views
-1
public void chooseInterface() { 

    int TEMP = Integer.parseInt(SelectInterface.getText()); 

    if (TEMP > -1 && TEMP < counter) { 
     index = 0; 
     Enable(); 
    } else { 
     // JOptionPane.showMessageDialog(null, Outside of 
     // Range.#interface=0+ 
     // (counter-1)+"."); 
     System.out.print("dfdfg"); 
    } 
    SelectInterface.setText(""); 
} 

錯誤是:異常在線程 「AWT-EventQueue的 - 0」 java.lang.NumberFormatException:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: 
    For input string: "" 

什麼是代碼的問題?如何解決這個錯誤?

+0

1)爲了更好地提供幫助,請發佈[MCVE]或[簡短,獨立,正確的示例](http://www.sscce.org/)。 2)請學習常用的Java命名規則(命名約定 - 例如'EachWordUpperCaseClass','firstWordLowerCaseMethod()','firstWordLowerCaseAttribute',除非它是'UPPER_CASE_CONSTANT')並且一致地使用它。 3)考慮使用帶'SpinnerNumberModel'的'JSpinner'而不是解析文本字段中的文本。4)IDE與問題無關,所以不要添加標籤。 –

回答

1

檢查空( 「」)值

SelectInterface.getText()

這會給NumberFormatException異常。此外,您可以先檢查空值並替換爲「0」。

相關問題