【发布时间】:2014-04-26 00:50:13
【问题描述】:
我在尝试使用 JFileChooser 扫描文本文件时遇到错误,将其添加到数组并将其中一个字符串解析为双精度数,将两个字符串解析为整数。是否与 addEmployee 方法将六个参数添加到 arrayList 的事实有关?这是代码...
else if (e.getSource()==readButton){
JFileChooser fileChooser = new JFileChooser("src");
if (fileChooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
{
empFile=fileChooser.getSelectedFile();
}
Scanner scan = new Scanner("empFile");
while(scan.hasNext()){
String[] rowData = scan.next().split(":");
if(rowData.length == 5){
rowData[4] = null;
fName = rowData[0];
lName = rowData[1];
position2 = rowData[2];
firstParam = Double.parseDouble(rowData[3]);
secondParam = Integer.parseInt(rowData[4]);
empNum = Integer.parseInt(rowData[5]);
}
else{
fName = rowData[0];
lName = rowData[1];
position2 = rowData[2];
firstParam = Double.parseDouble(rowData[3]);
secondParam = Integer.parseInt(rowData[4]);
empNum = Integer.parseInt(rowData[5]);
}
if (position2.equals("Manager")){
c.addEmployee(fName, lName, position2, firstParam, 0, empNum);
}
else if(position2.equals("Sales")){
c.addEmployee(fName, lName, position2, firstParam, 0, empNum);
}
else{
c.addEmployee(fName, lName, position2, firstParam, secondParam, empNum);
}
}
}
约翰:史密斯:制造:6.75:120:444
贝蒂:怀特:经理:1200.00:111
Stan:Slimy:Sales:10000.00:332
贝蒂:Boop:设计:12.50:50:244
【问题讨论】:
-
在此处发布堆栈跟踪/错误
-
也是你正在解析的文件的内部
-
对不起,堆栈跟踪/错误是什么?而且我不只是解析数组的 [3]、[4] 和 [5] 文件。
-
java给你的错误复制粘贴到这里,我们可以检查一下
-
线程“AWT-EventQueue-0”中的异常 java.lang.ArrayIndexOutOfBoundsException: 1 at GUI$aListener.actionPerformed(GUI.java:329) 这是错误所在,第 329 行是 lName =行数据[1];
标签: java arrays jfilechooser