Java FrameDemo Error: Could not find or load main class

1.2k views Asked by At

I'm starting to learn Java, and I am attempting to run the FrameDemo tutorial code found here: https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html

I can compile fine with javac FrameDemo.java but when I try to run it with java -cp . FrameDemo I get this error:

Error: Could not find or load main class FrameDemo

I thought it was my classpath so I tried java -cp D:\projects\framedemo FrameDemo and got the same error.

Then I tried recompiling with javac -cp . FrameDemo.java and javac -cp D:\projects\framedemo FrameDemo.java and still got the same error when running java -cp . FrameDemo and java -cp D:\projects\framedemo FrameDemo. I also tried running java -cp . FrameDemo.class just for the heck of it.

Always I get Error: Could not find or load main class FrameDemo

What am I doing wong here? I've just downloaded and installed the latest JDK. The source code is exactly what is in the demo link above.

1

There are 1 answers

3
Chand Priyankara On BEST ANSWER

move all your .class files to a folder 'components'. Then run this:

java components/FrameDemo

or

remove package components; from your source file, recompile and run :

java FrameDemo