'get'方法在调用时返回null

时间:2015-03-17 01:15:08

标签: java get null set

我试图将用户的名称返回到我已设置的另一个类,但是当调用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);
}

0 个答案:

没有答案