Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

java runtime problems

Thread view: 
Johnny Danger - 21 Sep 2007 07:00 GMT
Hello all.  I have a very simple problem.  I am seeking to develop
java apps on mepis linux (ver. 3.4-3).  I have installed jdk 1.6.0 and
i am having runtime error problems.  It seems like a simple matter,
but i do not know how to solve the problem i am having.  I have
compiled the following code directly from the sun website...

package start;

/*
* HelloWorldSwing.java requires no other files.
*/
import javax.swing.*;

public class HelloWorldSwing {
   /**
    * Create the GUI and show it.  For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    */
   private static void createAndShowGUI() {
       //Create and set up the window.
       JFrame frame = new JFrame("HelloWorldSwing");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       //Add the ubiquitous "Hello World" label.
       JLabel label = new JLabel("Hello World");
       frame.getContentPane().add(label);

       //Display the window.
       frame.pack();
       frame.setVisible(true);
   }

   public static void main(String[] args) {
       //Schedule a job for the event-dispatching thread:
       //creating and showing this application's GUI.
       javax.swing.SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               createAndShowGUI();
           }
       });
   }

}

when i compile, nothing seems to be wrong...

Aesotericon@5[HelloWorldSwing]$ ls
HelloWorldSwing.java
Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
bin/javac HelloWorldSwing.java
Aesotericon@5[HelloWorldSwing]$ ls
HelloWorldSwing$1.class  HelloWorldSwing.class  HelloWorldSwing.java
Aesotericon@5[HelloWorldSwing]$

when i try to run the program the following happens...

Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
bin/java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing (wrong name: start/HelloWorldSwing)
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
       at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)
       at java.net.URLClassLoader.defineClass(URLClassLoader.java:
260)
       at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
       at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
276)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)
Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
bin/java .HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: /
HelloWorldSwing
Aesotericon@5[HelloWorldSwing]$ unset CLASSPATH
Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
bin/java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing (wrong name: start/HelloWorldSwing)
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
       at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)
       at java.net.URLClassLoader.defineClass(URLClassLoader.java:
260)
       at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
       at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
276)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)
Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
bin/java .HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: /
HelloWorldSwing

As you all see, I have tried several methods of running the program,
but it will not work.  I feel like a simpleton, but does anyone have
any suggestions? It seems that java is having a hard time finding
my .class file.  I dunno...

J.P.
Gordon Beaton - 21 Sep 2007 07:10 GMT
> when i try to run the program the following happens...
>
> Aesotericon@5[HelloWorldSwing]$ /home/Aesotericon/Documents/jdk1.6.0/
> bin/java HelloWorldSwing
> Exception in thread "main" java.lang.NoClassDefFoundError:
> HelloWorldSwing (wrong name: start/HelloWorldSwing)

Because of the package statement ("package start") the name of the
class is "start.HelloWorldSwing". That's what java is trying to tell
you with the somewhat cryptic message above.

Either remove the package statement from the source code (and
recompile), or run it like this instead:

 java start.HelloWorldSwing

This is a good introduction to using Java packages:

 http://www.yoda.arachsys.com/java/packages.html

/gordon

--
Johnny Danger - 21 Sep 2007 07:55 GMT
> > when i try to run the program the following happens...
>
[quoted text clipped - 19 lines]
>
> --

voila!  thank you!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.