Java 输入字符串的数字格式异常

Java 输入字符串的数字格式异常,java,swing,user-interface,numberformatexception,Java,Swing,User Interface,Numberformatexception,目前我正在制作Attentience软件,但出现运行时错误。以下是我的代码:- public class gui015 extends JFrame { private JTextField[] tf; private JRadioButton a; private JRadioButton b; private JTextField t2; private JOptionPane op; private JButton c; public gui015() { super("Atte

目前我正在制作Attentience软件,但出现运行时错误。以下是我的代码:-

public class gui015 extends JFrame {

private JTextField[] tf;
private JRadioButton a;
private JRadioButton b;
private JTextField t2;
private JOptionPane op;
private JButton c;
public gui015()
{
    super("Attenedence");
    setLayout(new FlowLayout());
    t2 = new JTextField("Enter no. of students");
    add(t2);
    String s = t2.getText();
    int a = Integer.parseInt(s);
    tf = new JTextField[a];
    while(a>0)
    {
        tf[a] = new JTextField();
        add(tf[a]);
    }
}
我得到了一系列类似这样的错误:-

Exception in thread "main" java.lang.NumberFormatException: For input string: "Enter no. of students"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.parseInt(Integer.java:615)
    at tutorial.gui015.<init>(gui015.java:26)
    at tutorial.gui016.main(gui016.java:7)
线程“main”java.lang.NumberFormatException中的异常:对于输入字符串:“输入学生人数”
位于java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
在java.lang.Integer.parseInt(Integer.java:580)处
在java.lang.Integer.parseInt(Integer.java:615)
在tutorial.gui015.(gui015.java:26)
位于tutorial.gui016.main(gui016.java:7)

@这不是NPE问题Joshi您认为字符串“输入学生人数”应该代表什么数字??提示:
新建JTextField(“输入学生人数”)
输入学生人数
填充
JTextField
,这样字符串就不会成为文本字段的标签,它将是文本字段的内容。@问题是文本字段将显示,然后用户将输入要创建的文本字段的编号。当您从构造函数中的文本字段中获取文本时,用户在尝试解析之前没有时间输入数字。您的程序必须等待用户键入。您可能需要一种方式,用户可以让程序知道“我现在已经键入了数字,现在创建了文本字段”。@ANS不是NPE问题Joshi您认为什么数字应该由字符串
“输入学生数量”
?提示:
新建JTextField(“输入学生数量”)
输入学生人数
填充
JTextField
,这样字符串就不会成为文本字段的标签,它将是文本字段的内容。@问题是文本字段将显示,然后用户将输入要创建的文本字段的编号。当您从构造函数中的文本字段中获取文本时,用户在尝试解析之前没有时间输入数字。您的程序必须等待用户键入。您可能需要一种用户可以让程序知道“我现在已经输入了号码,现在创建文本字段”的方式。