0

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!

1
  • Look into your packaging of your class and the way you call the class to execute. The correct format of running java program is "java -cp [classpath] [package path]/JavaClassName" Commented Jan 31, 2013 at 14:06

2 Answers 2

3

Try running the Java file from inside the newfolder/

cd newfolder/
java Simple
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This was exactly what I needed to get things running :)
1

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

package newfolder;

at the start.

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.