Error while trying to run a class

Asked

Viewed 386 times

4

This is my first post here on the stack, I’m having a hard time running this class in Netbeans. I’m using version 1.8.0_40 of Java, I’ve tried searching for some solution, but I can’t find.

public class Dialog1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        // TODO code application logic here
        JOptionPane.showMessageDialog(null, "Bem Vindo ao Java");
    }

}

when compiling this class it even gives as a success, but gives an error message

run: Error: Unable to locate or load main class dialog1.Dialog1 Java Result: 1 BUILT SUCCESSFULLY (total time: 1 according to)

Does anyone know what might be going on?

  • This error seems to be related to project configuration, if you created a Java project, see in the properties if it is set correctly to correct jre for execution.

  • 1

    I suggest trying to run the script from the command line. If you have no problems from the command line, it is something in the IDE itself.

2 answers

2

It may be that import is missing at the beginning of the file:

import javax.swing.JOptionPane;

0

Missing the import of the class JOptionPane. As already said by Victor, you can import it with import javax.swing.JOptionPane; at the beginning of the code. But since in this case you’re only using her once, you could do so:

javax.swing.JOptionPane.showMessageDialog(null, "Bem vindo ao java!");

In this case, you are "calling" the class to be used only on that line. If you need it again, you will need to repeat this command.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.