扫描仪不会放入Objekt arrayList

时间:2017-03-30 17:53:03

标签: java

我的问题是我的扫描仪不会进入循环并在børnehaveArrayList中创建新的objets(Ansat)。

txt文件中的文字是:

ansat Casper Kern 5858 5858

ansat Trine Olsen 4747 4747

public class Load {

File file = new File("C:\\Users\\Ejer\\IdeaProjects\\tableSelv\\src\\Database");
Scanner scanner = new Scanner(file);

public Load() throws FileNotFoundException {

}

public void LoadAll(Børnehave børnehave) throws FileNotFoundException {
    while (scanner.hasNext()) {
    String temp = scanner.next();
    if (temp.equals("ansat")) {
        børnehave.getAnsatArrayList().add(
                new Ansat(parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next())
                )
        );

    }
    if (temp.equals("barn")) {
        børnehave.getBørnArrayList().add(
                new Barn(parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next()),
                        parsePropertiesString(scanner.next())
                )
        );

    }
}

}

public StringProperty parsePropertiesString(String s) {

    StringProperty p = new SimpleStringProperty();
    p.setValue(s);
    return p;
}

}

public class Ansat {
    StringProperty firstName = new SimpleStringProperty("","firstName","");
    StringProperty lastName = new SimpleStringProperty("","lastName","");
    StringProperty password = new SimpleStringProperty("","password","");
    StringProperty birthday = new SimpleStringProperty("","birthday","");

    public Ansat(StringProperty firstName, StringProperty lastName, StringProperty password, StringProperty birthday) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.password = password;
        this.birthday = birthday;
    }

0 个答案:

没有答案