Reputation: 793
In NetBeans 8.0.2 I've done a simple "Hello World" class that compiles and everything is fine.
public class OOP_HW3 {
public static void main(String[] args) {
System.out.println("Hi ");
}
}
On the other hand when I navigate to this folder with console and run:
$ javac OOP_HW3.java // OK
$ java OOP_HW3
Exception in thread "main" java.lang.NoClassDefFoundError: OOP_HW3 (wrong name: oop_hw3/OOP_HW3)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
....
I can easily run this file with console in any other directory, but here in the NetBeans project gives me error. What am I missing ?
Upvotes: 0
Views: 53
Reputation: 37023
Run the following commands from where you are running current command like:
cd ..
java oop_hw3.OOP_HW3
Since you are using package, you need to be on one top i.e. parent directory and then run with fully qualified package name followed by class where you define main method.
Upvotes: 2
Reputation: 137398
Remove the package
definition from the top of your java file.
Upvotes: 0