I'm using Notepad++ to write code, and command-prompt to compile and run the file on Windows 7. The problem I'm having is when
testing packages I keep getting NoClassFoundError. From what I
discovered this error has something to do with a missing classpath (I think?)...The compiled class file is in the same folder as the source file.
The following is a simple class with the package folders included:
The project folder 'JavaHandCode' is on the C:\ drive. The class compiles without issue, but when I try to run the class I get the error below...
C:\javahandcode\mainpackage\package1>javac TestPackage1.java
C:\javahandcode\mainpackage\package1>java TestPackage1
Exception in thread "main" java.lang.NoClassDefFoundError: TestPackage1 (wrong
name: javahandcode/mainpackage/package1/TestPackage1)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
C:\javahandcode\mainpackage\package1>
The really puzzling part is this; when I delete the package from the source code, the newly compiled file executes correctly.
Would really appreciate help with this, thanks!