-1

i'm a java - novice and am trying to run the following code from docs.oracle: https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/layout/BoxLayoutDemoProject/src/layout/BoxLayoutDemo.java

I'm compiling through cmd, have latest jdk, "path" - variable contains both jdk/bin and jre/bin and the .java file compiles well or at least doesn't report an error and produces .class file, which I see in folder. When I try to run the class, however, I tend too get :

Error: Could not find or load main class layout.BoxLayoutDemo Caused by: java.lang.ClassNotFoundException: layout.BoxLayoutDemo

Suspects?

yrz
  • 57
  • 2
  • 10

1 Answers1

0

you did not create package layout, but you are importing it, so either create layout package or remove it.

save class BoxLayoutDemo in folder layout

The Scientific Method
  • 2,374
  • 2
  • 14
  • 25
  • without the "package layout" statement compiled, i get the same error – yrz Sep 15 '18 at 09:16
  • folder "layout" is also tried out, same result – yrz Sep 15 '18 at 09:20
  • 1
    CLASSPATH issue. I have recently installed tomcat and set "classpath" for first time for tomcat's servlet-api.jar, without adding my working dir to classpath. now i have added it, restart, and it executes. THANKS FOR THE LINKS ABOVE ! – yrz Sep 15 '18 at 15:31