views:

47

answers:

2

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.

A: 

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.

ring bearer
A: 

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 ;)

BalusC
I'm using tomcat 6.0 with eclipse. can you help me do it?
hamam
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 ?
hamam
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.
BalusC
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.
hamam
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).
BalusC
it is turned on. I was redeploying and restarting tomcat at every turn. I cleaned tomcat's working directory and now I cant even access jsp's
hamam
Sounds like a pretty serious problem. Maybe Eclipse is messed up. Sorry, I don't know other solutions than just cleaning/reinstalling all the stuff the proper way.
BalusC