• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For code see:

my .java file is in c:\jdk\bin
my .class file is in c:\jdk\bin

javac HelloWorldSwing.java

runs with no errors (jse

java HelloWorldSwing

generates NoClassDefFoundError

I fail to understand why this is generated when the files are in the current directory. I've tried set CLASSPATH=C:\jdk\bin and then running java but i obtain the same result. I am positive this is not a typo. I had this problem many years ago when i first started Java, but haven't used it in years and am starting it up again. What am I missing? I've looked through the forum and the only think i haven't done is set a classpath environment which I dont (and others) think is necessary.

Thanks for your explanations. I created a start folder in the root. I could not run javac from anywhere but c:\jdk\bin.

Running javac c:\start\HelloWorldSwing.java in c:\start created the 2 class files.

Typing java start.HelloWorldSwing from bin folder still generated same error. java HelloWorldSwing generated same thing. java -classpath c:\start HelloWorldSwing also failed.

This seems so silly. Why does javac respond so easily to a directory path while java seems to be so clueless (like me).

Commenting out the package start; line allows the command

java -classpath c:\start HelloWorldSwing

to work. Thanks again for your assistance.
[ July 30, 2008: Message edited by: Francesca Gibbons ]
[ July 30, 2008: Message edited by: Francesca Gibbons ]
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this url:
Posts: 79231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope Francesca can read Portuguese, Camilo!

Welcome to JavaRanch

Don't put your own code into the bin directories; those are reserved for executable files from the Java installation. Put your code in its own directory, maybe a Java folder inside my Documents.

The file you have quoted has a package declaration. That means it will be in a folder called "start".
The way I would execute it is to put the .java file inside the Java folder and navigate to that folder then invoke
"javac -d . HelloWorldSwing.java"

The -d bit instructs the compiler to create a directory (if necessary) and the "." bit means to look for source files in the current directory.

The other way is to use the mkdir command to create a folder called start, put the .java file in there, compile it from inside the start folder without -d and .

In both cases, go outside the start folder and start the application with this command

java start.HelloWorldSwing

Good luck with it.
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic