java arraylist 问题
筱周 2010-02-27 04:09:23 if (e.getSource() == btnIdSelect) {
String number = txtIdSelect.getText();
try {
File file = new File("D:\\test.txt");
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
while (br.ready()) {
String line = br.readLine();
ArrayList al = new ArrayList();
if (line.contains(number)) {
al.add(line);
System.out.println(al);
}
String s3 = al.toString();
String[] s4 = s3.split("\\;");
for(int i = 0;i<s4.length;i++){
System.out.println(s4[i]);
}
}
br.close();
isr.close();
fis.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
这是一个查询按钮,根据输入学号查找到那学号所在的那行字符串
现在的问题是我把arraylist转换成String 再把String根据;号分割成String[];
为什么我打印出来的结果是这样的?
[]
[]
[]
[]
[]
[]
[]
[111;888;111;11;111;111;]
[111
888
111
11
111
111
]
问题补充:[]一起10个 而且 String[]给返回到界面中
txtName.setText(s4[0]);
txtId.setText(s4[1]);
txtAge.setText(s4[2]);
txtSex.setText(s4[3]);
txtMobile.setText(s4[4]);
txtHomeAddress.setText(s4[5]);
为什么会出现这样的错误Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at FFrame$InquestAct.actionPerformed(StudentMessage.java:634)
也就是txtId.setText(s4[1])这句话报错!
而且界面中 txtName的显示为[]!
找个高手帮忙解决下这个问题!