SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist Fergal's Avatar
    Join Date
    Nov 2003
    Location
    Ireland
    Posts
    500
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Running Programs with Dialog Boxes

    I've just started learning Java as part of a college course and this is the first time I have posted in the Java section here on SPF. My OS is Windows XP and I'm using NetBeans IDE 7.0.1 for writing and running Java.

    I've tried to run the program below in NetBeans, but it gives me an error message.

    Code:
    import javax.swing.JOptionPane;
    
    public class WelcomeInMessageDialogBox {
        public static void main(String[] args) {
            // Dialog Box
            JOptionPane.showMessageDialog(null, "Welcome to Java");
        }
    }
    Is there an error in the program or do I need to run the code in a different way in order to make it work?

    The error message I receive is as follows;

    run:
    java.lang.NoClassDefFoundError: welcomeinmessagedialogbox/WelcomeInMessageDialogBox
    Caused by: java.lang.ClassNotFoundException: welcomeinmessagedialogbox.WelcomeInMessageDialogBox
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    Could not find the main class: welcomeinmessagedialogbox.WelcomeInMessageDialogBox. Program will exit.
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    Thanks!
    Fergal Crawley (Previous Username: Proudirish.com)
    Business Advice Forum - Webmaster and Business Forum
    < Get a free link & win $5,000
    Forum Coin New World Currency

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I compiled and ran the code at the command line just fine.

    c:\welcomeinmessagedialogbox\javac WelcomeInMessageDialogBox.java

    c:\welcomeinmessagedialogbox\java WelcomeInMessageDialogBox

    It looks like your runtime inside Netbeans is applying a generic package name when your code has none.

  3. #3
    SitePoint Evangelist Fergal's Avatar
    Join Date
    Nov 2003
    Location
    Ireland
    Posts
    500
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks iackay, unfortunately I don't know how to run the code from command line. Will try to figure that out.
    Fergal Crawley (Previous Username: Proudirish.com)
    Business Advice Forum - Webmaster and Business Forum
    < Get a free link & win $5,000
    Forum Coin New World Currency

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I gave you the commands to do so in my first post.

    You need to have the java\bin directory in your Windows PATH. Plenty of posts on the intertubez on how to do that.


Bookmarks

Posting Permissions

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