どのクラスが「タイプのために未定義」エラーを引き起こしていますか?

うん:

Eclipseは、最後の行に)のgetNameため(「タイプ雑用のために未定義」私に言っています。問題がどこにあるか私は理解していないです。私もそれは雑用クラスから名前を引くしようとしている、雑用のクラスがありますか?またはそこに何かが間違って私の人々のクラスにいるのですか?(また、雑用クラスを追加)

        System.out.printf("%s's Chores: %n", person.getName());
        for(int i=0; i<person.getNumChores(); i++) {
        System.out.println(person.getChores()[i].getName()); //error here
        }

人クラス:

public class People {
    private Chore chores[] = new Chore[48];
    private int numChores = 0;

    private final String name;
    private final int birthYear;
    private int age;

    public void addChore(Chore chore) {
        if(numChores == 48) {
            System.out.println("All chores have been assigned.");
        }
        else {
            chores[numChores++] = chore;    
        }
    }

    public People(String name, int birthYear, int age) {
        this.name = name;
        this.birthYear = birthYear;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getBirthYear() {
        return birthYear;
    }

    public int setAge(int birthYear) {
        int age = 2020 - birthYear;
            return age;
        }

    public int getAge(){
        return age;
    }

    public int getNumChores() {
        return numChores;
    }

    public Chore[] getChores() {
        return chores;
    }  
}

ここで雑用クラスは次のとおりです。

public class Chore{

    private final String choreName; 
    private final String difficulty;
    private final String timesPerWeek;
    private String location;
    private String assigned;

    public Chore(String location, String choreName, String timesPerWeek, String difficulty){
       this.location = location;
       this.choreName = choreName;
       this.timesPerWeek = timesPerWeek;
       this.difficulty = difficulty;
       this.assigned = "N";
    }

    public Chore(String choreName, String timesPerWeek, String difficulty){
       this(choreName, timesPerWeek, difficulty, "Whole house");      
       this.assigned = "N";
    }

    public String getChoreName(){
        return choreName; 
    }    
    public String getDifficulty(){
        return difficulty;
    }

    public String getTimesPerWeek(){
        return timesPerWeek;
    }
    public String getLocation(){
        return location;
    }

    public String setAssigned(){
        String assigned = "Y";
        return assigned;
    }

    public String getAssigned(){
        return assigned;
    }
}
アービンド・クマールのAvinash:

あなたは持っていないgetName()メソッドの内部をChore

置き換えます

System.out.println(person.getChores()[i].getName());

とともに

System.out.println(person.getChores()[i].getChoreName());

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=378889&siteId=1