次のプログラムはNetbeansIDEで正常に実行されますが、コマンドプロンプトから実行しようとすると、
Exception in thread "main" java.lang.NoClassDefFoundError: Gcd (wrong name: algo
rithms/Gcd)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
package algorithms;
public class Gcd {
public static int ComputeGcd(int number1, int number2){
if(number2 == 0){ return number1;}
else{
int remainder = number1 % number2;
return ComputeGcd(number2,remainder);
}
}
public static void main(String[] args) {
int a = 32;
int b = 12;
System.out.println(ComputeGcd(a,b));
}
}