0

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 ?

3
  • You have no package declaration above public class OOP_HW3? Commented Mar 29, 2015 at 14:38
  • I have actually - package oop_hw3; Commented Mar 29, 2015 at 14:39
  • 1
    That explains it. :-) Commented Mar 29, 2015 at 14:42

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Remove the package definition from the top of your java file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.