我正在使用 Java S2SE 制作一个简单的原型项目。目标是制作一个文本文件,逐行读取,填充链接列表,然后要求用户输入名字和名字。
文本文件格式为:
名字 名字 名字 移动 家 mobile2 办公室
contact1contact2 手机之家 mobile2s 办公室
我连接文本文件中的名字和第二个名字。
然后我要求用户输入名字和名字,并使用这两个字符串的连接,将搜索填充的链接列表。无论出现包含具有这些名字和第二个名称的字符串的节点,拆分该节点并显示该节点的结果
我的代码是:
try {
String fullname;
String mobile;
String home;
String mobile2;
String office;
Node current=first;
while(current.data == null ? key !=null : !current.data.equals(key)) {
String splitter[]=current.next.data.split(" ");
//fullname=splitter[9];
mobile=splitter[1];
home=splitter[2];
mobile2=splitter[3];
office=splitter[4];
if(current.next.data.split(" ")==null?key==null:){
mobilefield.setText(mobile);
homefield.setText(home);
mobilefield2.setText(mobile2);
officefield.setText(office);
} else {
throw new FileNotFoundException("SORRY RECORD NOT LISTED IN DATABASE");
}
break;
}
} catch(Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage()
+"\nPLEASE TRY AGAIN !","Search Error", JOptionPane.ERROR_MESSAGE);
}
问题是一切都很好,但是对于列表中的第一个和直到第 n-1 个节点的搜索出错,但在此搜索中没有到达最后一个节点。