• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Big problem with Sun online tutorial: Swing

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The very first exercise in this trail is the compiling and execution of a little application called HelloWorldSwing. I have copied the code from the tutorial and pasted it into emacs. I then compiled it into the same directory into which I had saved the source code. The compile was clean; I checked to be sure that the source and class files were in the same directory (after the execution attempt bombed horribly). I have checked the FAQs in the tutorial; they are no help. Everything that I have copied from Head First Java as well as the stuff that I have written myself has run all right (within findable errors on my part, like null pointers). Could someone please suggest where I should look to get a handle on this?

I am using Windows XP. The errors are as follows:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing (wrong name: start/HelloWorldSwing)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.define Class(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

The source code is:

 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The declared package is "start," so this this needs to be in a directory (folder) called "start." Once it's compiled with this package declaration, the fully-qualified name is start.HelloWorldSwing. Use this when running.

At the command prompt, change directories so that the current directory is the directory that contains start. For example, suppose the "start" directory is under your own directory called myJava. Then tell javac where to find the file by compiling with:

...myJava> javac start/HelloWorldSwing.java

And run by giving java the fully-qualified name:

...myJava> java start.HelloWorldSwing

Ref: JLS 6.7...

The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.


[ July 26, 2007: Message edited by: marc weber ]
 
Jinny Morris
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
marc -

ooooooops - there should be a Graemlin demonstrating extreme embarrassment!

I haven't got to packages yet in Head First Java - so hoped I could just ignore the "package" statement at the beginning. Now I know better. Commenting it out worked just fine!

With much chagrin,
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jinny Morris:
...hoped I could just ignore the "package" statement at the beginning. Now I know better. Commenting it out worked just fine! ...


Removing the package declaration will work for now, but don't wait too long to get familiar with packages.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic