简体   繁体   English

线程“ Thread-3”中的异常java.lang.NumberFormatException:对于输入字符串:“”

[英]Exception in thread “Thread-3” java.lang.NumberFormatException: For input string: “”

So my main plan is to have a GUI with a button and two jTextFields . 所以我的主要计划是创建一个带有按钮和两个jTextFields的GUI。 When the button is pressed it starts a new thread of the Runnah class I have made. 当按下按钮时,它将启动我创建的Runnah类的新线程。 The Runnah class is suppose to get the input from the text fields; 假设Runnah类是从文本字段获取输入的。

The Runnah class then gets a NumberFormatException when I run gui.getSeconds(); 然后,当我运行gui.getSeconds();时, Runnah类将获得NumberFormatException gui.getSeconds();

The MainGUI Class MainGUI类

public class MainGUI extends javax.swing.JFrame {

Runnah runnah;
Thread thread;

public MainGUI() {
    initComponents();
    //runnah = new Runnah();
}                        

private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    try {
        runnah = new Runnah();
    } catch (AWTException ex) {
        Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    thread = new Thread(runnah);
    thread.start();
}                                           

public String getInput(){
    String temp = textInp.getText();
    return temp;
}
public int getSeconds(){
    return Integer.parseInt(secInp.getText());
}

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
                new MainGUI().setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JTextField secInp;
private javax.swing.JButton startButton;
private javax.swing.JTextField textInp;
// End of variables declaration                   
}

The Runnah Class 朗纳课

public class Runnah implements Runnable{

private MainGUI gui;

private Robot robot;

public Runnah() throws AWTException{
    this.robot = new Robot();
    gui = new MainGUI();
}

public Runnah(Robot robot) {
    this.robot = robot;
}

@Override
public void run() {

    String temp = gui.getInput();
    CharSequence input = temp;
    int seconds = 1;
    seconds = gui.getSeconds() * 1000;

    robot.delay(seconds);
}

If any more information is needed please let me know. 如果需要更多信息,请告诉我。

我只是没有引用现有的MainGUI类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java-线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“”位于 - java - Exception in thread “main” java.lang.NumberFormatException: For input string: “” at 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:Java中的“” - Exception in thread “main” java.lang.NumberFormatException: For input string: “” in Java 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“ 0.06” - Exception in thread “main” java.lang.NumberFormatException: For input string: “0.06” 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“8/3/2012” - Exception in thread "main" java.lang.NumberFormatException: For input string: "8/3/2012" 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“” - Exception in thread “main” java.lang.NumberFormatException: For input string: “” 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“0.353” - Exception in thread “main” java.lang.NumberFormatException: For input string: “0.353” 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串 - Exception in thread “main” java.lang.NumberFormatException: For input string 线程“main”中的异常 java.lang.NumberFormatException:对于输入字符串:“38” - Exception in thread "main" java.lang.NumberFormatException: For input string: " 38" 线程“ main”中的异常java.lang.NumberFormatException:对于输入字符串:“” Array - Exception in thread “main” java.lang.NumberFormatException: For input string: “” Array 线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:“3291105000” - Exception in thread “main” java.lang.NumberFormatException: For input string: “3291105000”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM