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.

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;

java.lang.NoClassDefFoundError: welcomeinmessagedialogbox/WelcomeInMessageDialogBox
Caused by: java.lang.ClassNotFoundException: welcomeinmessagedialogbox.WelcomeInMessageDialogBox
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
Could not find the main class: welcomeinmessagedialogbox.WelcomeInMessageDialogBox. Program will exit.
Exception in thread “main” Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


I compiled and ran the code at the command line just fine.


c:\welcomeinmessagedialogbox\java WelcomeInMessageDialogBox

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

Thanks iackay, unfortunately I don’t know how to run the code from command line. Will try to figure that out.

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.