【发布时间】:2017-03-29 17:05:15
【问题描述】:
我的代码基于 gui,我尝试在 gui 上运行,但没有成功。 公共类 SecondFrame 扩展 JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SecondFrame frame = new SecondFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public SecondFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 612, 469);
contentPane = new JPanel();
contentPane.setBackground(Color.BLUE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Success !");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 38));
lblNewLabel.setBounds(201, 120, 233, 74);
contentPane.add(lblNewLabel);
JButton btnGenerateGraph = new JButton("GENERATE GRAPH");
btnGenerateGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
FileReader reader = new FileReader("rn.txt");
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
**here i try to convert line that i has read to integer**
while ((line = bufferedReader.readLine()) != null) {
System.out.println(Integer.parseInt(line));
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
btnGenerateGraph.setFont(new Font("Tahoma", Font.BOLD, 21));
btnGenerateGraph.setBounds(168, 221, 245, 59);
contentPane.add(btnGenerateGraph);
}
}
这是错误: 线程“AWT-EventQueue-0”中的异常 java.lang.NumberFormatException:对于输入字符串:“/”
我的 rn.txt 文件:
29 44 15 17
【问题讨论】:
-
文件 RN.txt 中有一行包含字符“/”,您正试图将其解析为数字。做不到。
-
29 44 15 17 我的文件看起来像这样 .. 没有字符“/”
-
在你的 System.out.println(Integer.parseInt(line));行,插入一个 System.out.println(line);这将向您显示该行包含的内容。
标签: java user-interface