I have an issue with NoClassDefFoundError
. I am using interfaces, and no class definition should be available:
package code;
public interface Co
Check the static initialization of this class. Look here: what is the difference between NoClassDefFoundError and ClassNotFoundException.
java.lang.NoClassDefFoundError: code/Constants
does not mean that the Constants class is not in the CLASSPATH. In fact it is quite the opposite. It means that the class was found by the ClassLoader, however when trying to load the class, it ran into an error reading the class definition. This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader.
From your question I see that the compiled Constants
interface resides in a jar which is different from the jar/location of the implementing classes. So you should be able to execute your application like this:
java -cp /path-to-jar/JarContainingConstants.jar my.application.Main
(replace the names with your real names)
If you've added the other classes to another jar and then if you made that jar executable and then if you tried to run it with java -jar MyApplication.jar
, then any the classpath defined outside the executed jar is ignored. But the above command shoud work with any jar (executable or not).
from comment
[alef@localhost ~]$ java -cp /../code-misc.jar /.../MultiDoc.jar
Exception in thread "main" java.lang.NoClassDefFoundError: /.../MultiDoc/MultiDoc/jar
Caused by: java.lang.ClassNotFoundException: .home.
... .MultiDocDateMathcer.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
...
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: /.../MultiDoc/MultiDocr.jar.
Program will exit.
You call is definitely incorrect. Do it like this (UPDATE):
java -Dgate.home=/my/new/gate/home/directory -cp gate.jar;code-misc.jar;MultiDoc.jar gate.Main
Note that there are two different exceptions that sound very similar: ClassNotFoundException and NoClassDefFoundError.
The first exception occurs in the simple case that the JVM looks for "packageB.ClassA" and can't find it in the search path. There are a few other cases, I suspect, but fairly rare.
The second exception occurs mostly when an appropriately-named class file is found, but for some reason it can't be used. There are two primary reasons for this:
If you have somedirectory/code
in your classpath, then that's wrong. You always need the base directory in your classpath (in this case it would be somedirectory
). Java itself will search those roots for a directory called code
containing a file called Constants.class
.
You might have it in your CLASSPATH when compiling but this does not guarantee that it is in the CLASSPATH when you run it. How do you run it?
Any Interface must declared inside class.
public class Calbacks {
public interface IBaseFragmentInterface {
void NotifyMainActivity();
}
}
*I very long find resolution of this problem, but i find resolution independently by the method of scientific poking