我有一堂课,上面有人员名单。我创建了一个 PersonBeholder 类(在挪威语中是 PersonContainer 的意思)。我还有一个 Person 类,以及一个建立人与人之间关系的主类。当我尝试引用主要课程之外的人员的一般列表时,我遇到了问题。
class TestPersoner{
public static void main (String [ ] args){
**PersonBeholder pl = new PersonBeholder();**
Person Emil = new Person("Emil");
Person Nils = new Person("Nils");
pl.settInnPerson(Emil); //this populates the list
pl.settInnPerson(Nils);
}
}
现在当我尝试从外部引用 PersonBeholder pl 时遇到问题:
public void blirVennMed(Person p){
if(!pl.erIbeholder(p.hentNavn())) System.out.print("This is not going to work");
//this does check if there is someone in the container named p.hentNavn()
}
输出
TestPersoner.java:26: error: cannot find symbol
if(!pl.erIbeholder(p.hentNavn())) System.out.print("This is not going to work");
^
symbol: variable pl
location: class Person
1 error
现在我这样做了:
class TestPersoner{
public static PersonBeholder pl = new PersonBeholder();
public static void main (String [ ] args){
Person Emil = new Person("Emil");
Person Nils = new Person("Nils");
pl.settInnPerson(Emil); //this populates the list
pl.settInnPerson(Nils);
}
}
它仍然不起作用。