java 提示错误Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

public class SaveExcel
static ArrayList<String> ar = new ArrayList<String>();
public static void lastLine() {
try {
readFile("C://Users//wan//Desktop//01-01-01.tc.txt");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String readFile(String st) throws Exception {
File file = new File(st);
FileReader fr = new FileReader(file);
BufferedReader bw = new BufferedReader(fr);
String str = null;
while ((str = bw.readLine()) != null) {
ar.add(str);
}
System.out.println(ar.get(ar.size() - 1));
return ar.get(ar.size() - 1);
}
public void writeExcel(String path) throws Exception {
WritableWorkbook wb;
String x = readFile(path);
try {
wb = Workbook.createWorkbook(new File(path));
WritableSheet ws = wb.createSheet("sheet1", 0);
for (int i = 3; i < 100; i++) {
try {
if (x == "Success") {
jxl.write.Label labelN = new jxl.write.Label(3, i + 3, "OK");
ws.addCell(labelN);
} else {
jxl.write.Label labelN = new jxl.write.Label(3, i + 3, "NG");
ws.addCell(labelN);
}
} catch (Exception e) {
}
}
wb.write();
wb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
public static void main(String args[]) throws Exception {
new SaveExcel().writeExcel("C:\\Users\\wan\\Desktop\\testresult.xls");
}
}

你好:你传递的数组越界了,你是不是没传递值啊,之后直接读取的;结果就报错了。
System.out.println(ar.get(ar.size() - 1));
return ar.get(ar.size() - 1);追问

你好,请问如何修改才能达到想要的结果。
结果是在excel里面根据txt最后一行的内容,输入OK或者NG。

温馨提示:答案为网友推荐,仅供参考
相似回答