Search code examples
javanetbeanscompilationenumsnosuchmethoderror

Java NoSuchMethodError in enum


I just added a method to an enum. Whenever I invoke that method I get a NoSuchMethodError:

public enum PHASE {
  PHASE1,
  PHASE2(false),
  PHASE3;

  private boolean present = true;

  PHASE() {
  }

  PHASE(boolean present) {
    this.present = present;
  }

  public boolean isPresent() {
    return this.present;
  }
}

public void foo(PHASE phase) {
  if (phase.isPresent()) {
...

Here phase.isPresent throws a NoSuchMethodError after clean/build. What am I missing?

--

UPDATE: Netbeans has two cache folders. One was empty, the other one was not. That is my bad, apparently I didn't put enough effort into the caching issue. Unfortunately I cannot downvote my own question...


Solution

  • It is possible that this is Netbeans specific issue. Especially if you use "Compile on save option" and have a big project with a lot of dependencies. See here for details.

    I had a very similar problem with such (maven-based) project almost on a daily basis, and found a solution using the above link. Better to say variations of solution. Try it like this:

    please feedback.