简体   繁体   中英

Unable to run Java program

I'm having trouble running my very first piece of java. I was able to compile it and produce a .class file, but then I was unable to run it for some reason. It might have something to do with the directory path. The file name is "Simple" and I have this saved in a folder called "newfolder".

I was able to compile Simple.class by typing in "javac newfolder/Simple.java", but when I typed in "java newfolder/Simple", this message appeared:

java: exception in thread “main” java.lang.NoClassDefFoundError: newfolder/Simple (wrong name: Simple)

Here is the original code that I typed in:

// This is a simple Java program.

public class Simple
{
   public static void main(String[] args)
   {
     System.out.println("Hello World");
   }
}

I think that the answer here is up my alley, but I've somehow been unable to get it to work for me, so any assistance would be greatly appreciated. Thanks in advance!

Try running the Java file from inside the newfolder/

cd newfolder/
java Simple

I suspect you want to use an IDE which sets up these things for you but you need

package newfolder;

at the start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM