views:

181

answers:

3

I have two classes inside a package. Both call a method from another class, one works perfectly fine and the other gives the error java.lang.ClassNotFoundException and the error java.lang.NoClassDefFoundError: com/google/common/base/Predicate

The class path should be the same for both as they are in he same package so I can't figure out why one has access to the class and the other doesn't?

thanks in advance for any help given.

A: 

You get both a ClassNotFoundException and a NoClassDefFoundError?? The first usually occurs when you try to load a class via reflection, while the second implies that the class was found during compilation but is not accessible at runtime.

The class path should be the same for both as they are in he same package

The class path has absolutely nothing to do with packages. Can you show us some of your actual code and how you run it? It's hard to diagnose the problem otherwise.

Michael Borgwardt
+1  A: 

Are you sure that your first class uses Predicate from Google Collections? (as far as I know Apache Commons have interface with the same name, maybe there are different imports in your classes, or maybe you don't use Predicate at all in the first class).

Anyway, the problem is that the program cannot find jar with Google Collections lib in its classpath.

Roman
the class that is called by both methods is the one that uses the predicate from from Google collections.That is why I am confused, if one can acess that method and predicate works, why cant the other access it and predicate work?
pie154
A: 

Ok, so I have solved the problem, but not quite sure how one class ran and was able to call the method and another wasn't. I was using eclipse IDE and I had used the inbuilt methods to edit he class path and had used the import JAR button rather than the import external JAR button when importing the Google collections. Can anyone think why importing as an External Jar rather than a JAR would make any difference?

pie154