Question

I have a project with different classes and packages as dependencies. Note that everything writte below occurs in one project.

I have a class that at some point runs the code getDiagramPanel().setRelationsPaintOrder(new Comparator() {.

getDiagramPanel() calls the method from DjtSheet.class, which is located in a dependency .jar-file. This method returns the DjtDiagramPanel object. I also have a DjtDiagramPanel.java file, which should override the one from the package and contains the method setRelationsPaintOrder().

In Java 7, this works fine. It correctly calls the method from the dependency, which returns the object in the format of the class which overrides the panelclass from the dependency package.

In Java 6 however, the panelclass from the dependency package is returned instead of the one from my project.

java.lang.NoSuchMethodError: com.dlsc.djt.gantt.DjtDiagramPanel.setRelationsPaintOrder(Ljava/util/Comparator;)V

Note that this message occurs at runtime! Compiling the project gives no errors.

How can I solve this?

Was it helpful?

Solution

This problem definitely means that you have a problem in class path. I guess that the problem is that class DjtDiagramPanel is duplicate and you have 2 different veraions: one that has method setRelationsPaintOrder and second that does not have. Apparently you compile code against the "good" version and run against the "bad" one.

When this happens you can probably change the order of class loading by playing with order of dependencies in project properties of eclipse, but it will just fail later (on production). So, you should find what is the root cause of the duplication.

First find these 2 versions of the same class. Then find how the bad version arrived to your classpath. It typically happes because of 3rd party dependencies. If you are using maven you can use dependency plugin to find the root cause and disable it using tag "exclusion".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top