I am using a jar file compiled in a different PC. When I run my program in Eclipse, I am getting NoSuchMethodError. I got to know its the problem of different buildpath and runtime path. I want to know how to set right this problem in Eclipse ( I am a newbie in Eclipse). Where and what should I change. Thanks in advance.
Asked
Active
Viewed 1,095 times
0
-
How did you put that `Jar`, the one that was built on some other `PC` in your eclipse project? – Mukul Goel Jul 01 '13 at 11:47
-
@MukulGoel Went to properties of my Project-> Java build path-> add external jars-> (Selected my jar) – user2500875 Jul 01 '13 at 11:49
-
1Post your error stack trace ! – Mukul Goel Jul 01 '13 at 12:02
-
Exception in thread "main" java.lang.NoSuchMethodError: x.y.z.a.b.method(ILcom/google/api/translate/Language;)V – user2500875 Jul 01 '13 at 12:08
3 Answers
0
You have taken over one jar, without all the other jars it depends on. You should inspect the build path at the "different PC" to see what comprises your JAR's classpath and replicate that on your machine.

Marko Topolnik
- 195,646
- 29
- 319
- 436
-
If it's depending on a missing library in the class path it would be a ClassNotFoundException instead of a NoSuchMethodError – Marvin Emil Brach Jul 01 '13 at 11:56
-
1@MarvinEmilBrach Where did you get that idea? `NoSuchMethodError` is what is thrown when the runtime attempts to on-demand load a class, triggered by a static dependency in the currently executing code. This is precisely what happens when a JAR which was available at compile time is missing at runtime. – Marko Topolnik Jul 01 '13 at 12:14
-
0
You have to include the JAR into you project: Project -> Properties Java Build Path -> Libraries -> Add Jar or Add external JAR...

LostBoy
- 948
- 2
- 9
- 21
-
-
If it's depending on a missing library in the class path it would be a ClassNotFoundException instead of a NoSuchMethodError – Marvin Emil Brach Jul 01 '13 at 11:56
0
From http://docs.oracle.com/javase/7/docs/api/java/lang/NoSuchMethodError.html:
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.
Regarding your explanation you have two different versions of a library you use. Probably its the rt.jar (standard runtime library of Java) which is older on your host (e.g. V 1.6) than on the host where the program was compiled (e.g. V 1.7)

Marvin Emil Brach
- 3,984
- 1
- 32
- 62
-
-
what's about other used libraries? post the stack trace then we could figure out... If it's depending on a missing library in the class path it would be a ClassNotFoundException instead of a NoSuchMethodError – Marvin Emil Brach Jul 01 '13 at 11:53
-
the class is existing, if i debug the code it is saying Source Not Found and is asking me to "Attach Source". The source file it is asking me is part of the jar file i attached to my project. what should i do? – user2500875 Jul 01 '13 at 12:02
-
If the source is contained in that jar then give eclipse that information while selecting the jar in the following dialog. But that will not help you, because you can only see the source. But there will be no such method in the specified class, that's what the Exception is pointing out. When the Exception get thrown, there should be a so called "stack trace": http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – Marvin Emil Brach Jul 01 '13 at 12:08
-
Exception in thread "main" java.lang.NoSuchMethodError: x.y.z.a.b.method(ILcom/google/api/translate/Language;)V – user2500875 Jul 01 '13 at 12:08
-
and the winning library is x.y.z.a.b! The used version of that library differs from the one used at compile time. Two possible solutions: find out which version of that lib was used to compile your program OR edit and recompile your program while using the version of the lib you have. (by the way: that's not a *stack* at all, its only it's first layer - the whole stack is going down much deeper: *at x.y.z.a.b.method2 at x.y.z.a.b.method3() at x.y.z.a.b.methodN() ... at x.y.z.a.b.main()) – Marvin Emil Brach Jul 01 '13 at 12:11