Error class not Found fixed but I don't understand why

java

#1

The file “HelloDemo.java” path is “/test/hello/HelloDemo.java”

package test.hello;
public class HelloDemo {
  public static void main(String[] args) {
      System.out.print("Hello!!");
  }
}

when I “run” it, an error occurred.

Building HelloDemo.java and running HelloDemo
Error: Could not find or load main class HelloDemo

Then, I changed the code.

//package test.hello;

public class HelloDemo {
  public static void main(String[] args) {
      System.out.print("Hello!!");
  }
}

when I “Run” it, code success output.

Building HelloDemo.java and running HelloDemo
Hello!!

I fixed an error, but I don’t konw why, I need help, Thank you!

If I want to keep the package uncomment, How to fix it?


#2

Thank you for sharing this it solved the same issue, my code ran fine on netbeans but when I move it to cloude 9 it wont run. As you mentioned removing the package (in my case):
package src;
solved my problem
I hope someone else can reply to the reason why this happens.