我试图将用户的名称返回到我已设置的另一个类,但是当调用getName时,返回null。我究竟做错了什么?
public class Investor {
private String firstName;
private String lastName;
public String getName(){
return firstName + " " + lastName;
}
public void setName(int userIndex){
ArrayList<String> firstNameList = new ArrayList<String>();
ArrayList<String> lastNameList = new ArrayList<String>();
String line = "";
try{
FileReader fr = new FileReader("investments.txt");
BufferedReader br = new BufferedReader(fr);
while((line = br.readLine()) != null) {
line.split("\\s+");
firstNameList.add(line.split("\\s+")[3]);
lastNameList.add(line.split("\\s+")[4]);
}
}
catch(IOException e){
System.out.println("File not found!");
}
this.firstName = firstNameList.get(userIndex);
this.lastName = lastNameList.get(userIndex);
}