[英]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.