Results 1 to 5 of 5
  1. #1
    mr_sandman is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default problems with swing example program

    Im writing a simple gui program i found in the java complete reference book. the code as far as i can tell is a carbon copy of whats found in the book. however i always get a runtime error when i run it.


    The code:

    package swing1;

    import javax.swing.*;

    class SwingDemo {

    SwingDemo() {JFrame jfrm = new JFrame("a simple swing application");
    jfrm.setSize(275, 100);
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    JLabel jlab = new JLabel("Swing means powerful GUIs");
    jfrm.add(jlab);
    jfrm.setVisible(true);}

    public static void main(String args[]) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() { new SwingDemo();
    }
    });
    }
    }

    the error:

    Exception in thread "main" java.lang.NoClassDefFoundError: swing1/Main
    Caused by: java.lang.ClassNotFoundException: swing1.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Java Result: 1

    any ideas of what is causing this error?

    thanks

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    How are you running the program? If it is on the command line then post the command you use and your working directory.

  3. #3
    mr_sandman is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    ive been running it using netbeans would you suggest running it on the command line?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    You need to modify Netbeans run command. It is trying to run a class called Main but your class is called SwingDemo.

  5. #5
    mr_sandman is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Swing Problems
    By niba10 in forum Advanced Java
    Replies: 5
    Last Post: 02-25-2011, 03:18 PM
  2. Simple swing program, help please!
    By N00Bie in forum New To Java
    Replies: 5
    Last Post: 02-17-2011, 06:16 PM
  3. Replies: 13
    Last Post: 12-06-2010, 06:57 AM
  4. need help in uploading images in swing program!!!
    By ashton in forum New To Java
    Replies: 10
    Last Post: 01-26-2009, 11:01 AM
  5. netbeans+swing = painting program?
    By yuriythebest in forum New To Java
    Replies: 3
    Last Post: 12-14-2008, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •