我编译成功了我的程序,但在运行它时遇到了未定义的类错误。奇怪的是我没有在myprogram中使用cern/colt/matrix/DoubleMatrix1D类(我用“grep”验证了这一点)。有人可以请指点我正确的方向吗?由于为什么java会抱怨一个没有使用的类?
$ javac -cp $(find ../resources/ -name "*.jar"|tr "\n" ":") myprogram.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ java myprogram
Exception in thread "main" java.lang.NoClassDefFoundError: cern/colt/matrix/DoubleMatrix1D
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: cern.colt.matrix.DoubleMatrix1D
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
注:
- DoubleMatrix1D是一个抽象类。
- 我在myprogram中使用了DoubleMatrix1D的子类'SparseDoubleMatrix1D'。
很明显你会在你的程序中使用它。请注意,当您编译程序时(编译器知道它们),您会在类路径中添加一堆jar文件,但在运行程序时不会。 – immibis 2015-02-07 23:26:29