简体   繁体   English

Java Iterator - 不能从静态上下文中引用非静态方法 getID()

[英]Java Iterator - Non-static method getID() cannot be referenced from a static context

Keep on getting this same error.继续收到同样的错误。

public int getNumberOfAmbulances(int area) {
    Iterator<Ambulance> it = ambulances.iterator();
    while(it.hasNext()) {
        Ambulance tk = it.next();
        return (Ambulance.getID());
    }
}

"Non-static method getID() cannot be referenced from a static context" “不能从静态上下文中引用非静态方法 getID()”

getID() in Ambulance class is not static that means it can only be accessed using an object. Ambulance 类中的 getID() 不是静态的,这意味着它只能使用对象访问。 Either make that method static or call getID() like this : tk.getID()要么将该方法设为静态,要么像这样调用 getID():tk.getID()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM