3

I have 2 projects linked and these 2 projects each have a package under them.

XProject -> XPackage -> XClass -> X1Method(); X2Method();

YProject -> YPackage -> YClass -> Y1Method();

I'm trying to call X1 and X2 methods from Y1 Method. I can call X1 Method but when I call X2 method I get a runtime error (java.lang.NoSuchMethodError:)

All methods are public and there is nothing wrong with method names. It is just nonsense to have one of them working while other is giving runtime errors.

Any help would be appreciated. Thanks.

3
  • 1
    What is your build system? Is it possible that you're building against an old version of XClass? Commented Apr 15, 2010 at 16:31
  • Could you post some example code to illustrate the problem? Commented Apr 15, 2010 at 16:32
  • I'm using tomcat 6.0 as the application server. Developing on Eclipse with JavaEE. Commented Apr 15, 2010 at 16:40

2 Answers 2

2

From the java.lang.NoSuchMethodError javadoc:

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

In other words, the runtime classpath doesn't contain the class with the desied method, while it was available in the compiletime classpath. Summarized: your classpath is messed up. Cleanup and align it. How to do it exacly depends on your environment.

Update: Thus, it's a Java EE webapplication in Eclipse? Assuming that the one is a Dynamic Web Project and the other is a normal Java Project, in the project properties of the Dynamic Web Project you need to add the normal Java Project in the Build Path and the Java EE Module Dependencies.

If that doesn't fix the problem, then most likely the appserver's or the JRE's default classpath is dirty. You'll need to remove any unnecessary project-related libraries from JRE/lib, JRE/lib/ext and Tomcat/lib and promise yourself that you don't touch those library paths anymore ;)

Sign up to request clarification or add additional context in comments.

7 Comments

I'm using tomcat 6.0 with eclipse. can you help me do it?
You're right it is a JavaEE webapplication. Y project is Dynamic Web Application X one is normal Java Project. Dynamic web project has X project in its build path. I dont know module dependencies but it was working with just build path. After I inserted new fucntions they didnt work. Is there a way to tell tomcat to use the latest version of X project ?
That is worked is likely misinterpretation or a messed up classpath. Add it to Java EE module dependencies, that's the only right way. I would however doubleverify if you didn't unnecessarily put "irrelevant" libraries in JRE's and Tomcat's classpath.
It is already added to the module dependencies. I guess that is why X1 method is still working. I dont think there are irrelevant libraries in JRE's or tomcat's classpath. But I'll check them.
To avoid the obvious: is Eclipse's automatic build turned on? (which should be the default, check Project menu). Did you redeploy the webproject and restart the server after changes? (to be sure that nothing has been cached/missed).
|
0

Very likely that you are compiling against some .class of XClass in your classpath. But the run time (probably linked project) has a different version of XClass. This is environment specific. You need to see what artifacts are in your classpath during compilation and what is being picked up during run;

As commented by others. Details regarding your IDE/Build system or even code is required to further answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.