2017-04-14 36 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”。

相关问题