1

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"

ernest_k
  • 44,416
  • 5
  • 53
  • 99
Sam Ward
  • 25
  • 3
  • 4
    Did you mean to use `return tk.getID();`? And why would you iterate if you're going to return the first value? – ernest_k Nov 18 '20 at 12:08
  • Does this answer your question? [What is the reason behind "non-static method cannot be referenced from a static context"?](https://stackoverflow.com/questions/290884/what-is-the-reason-behind-non-static-method-cannot-be-referenced-from-a-static) – Turamarth Nov 18 '20 at 12:09

1 Answers1

1

getID() in Ambulance class is not static that means it can only be accessed using an object. Either make that method static or call getID() like this : tk.getID()