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的显示为[]!
找个高手帮忙解决下这个问题!
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的显示为[]!
找个高手帮忙解决下这个问题!
解决方案 »
- 一个连接数据库的问题
- 谁有jdom的中文帮助文档啊,给我一份,实在没有英文也行
- 保存圆形图片的问题
- 关于this,不理解,再一个方法有些不理解,可以解释一下否
- 谁能给个线程安全和非线程安全的代码实例?
- 请求如何封装类---在线等
- 我写了一个简单的手表程序,但是还有一个问题,各位请进...
- 外部命令的问题
- Effective Java——并发 访问共享可变数据
- Java 用ImageIcon或者其他的从本地读取一张图片 然后在这张图片上用画笔Graphics根据坐标点来画原点
- 关于JRadioButton中fireActionPerformed里面的执行顺序的问题
- 迅雷多线程题求高手帮忙,代码有误
ArrayList<String> al = new ArrayList<Stirng>();
...
String[] strs = al.toArray();
如果这样写的话
Object o = al.get(0);
String s4 = o.toString();
会在Object o = al.get(0);这句话上报错!
你debug 跟踪一下,看list里面到底是什么东西,看下你塞进去的到底是什么类型。
你是怎么读文件的?