Question

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...

Était-ce utile?

La solution 2

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.

Autres conseils

This is probably an issue between your compile-time classpath and you run-time classpath. Your classes/jars files at runtime are not the same that you used at compile time.

Clean and rebuild your project to be sure.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top