Why this Java error occurred?

Asked By 0 points N/A Posted on -
qa-featured

Here's my 7-line code, supposedly making a dialog box saying "It worked!":

import javax.swing.*;
class MyFirstProgram {
public static void main(String[] arg) {
JOptionPane.showMessageDialogue;(nul… "It works!");
System.exit(0);
}
}

I get this error when trying to compile it using javac:

hello.java:4: error: cannot find symbol
JOptionpane.showMessageDialogue((null)…
(the arrow..) ^

I'm writing the code exactly how my textbook tells me, so why is this happening and how can I fix it?

SHARE
Best Answer by daistarz
Answered By 0 points N/A #92637

Why this Java error occurred?

qa-featured

Hello,

You can fix it easily. You have wrong method name and an extra semicolon as well.
It should be
JOptionPane.showMessageDialog( null,"It works");

Hope this will help.

Good Luck.

Best Answer
Best Answer
Answered By 0 points N/A #92638

Why this Java error occurred?

qa-featured

The error occurs because you have used a wrong method and wrong syntax along the line containing JOptionpane. You have written Dialog instead of Dialog and there should  be no semi colon after Dialog.

The brackets part should contain (null,"It works!").

Please try the following code.

import javax.swing.*;
public class MyFirstProgram {
public static void main(String[] arg) {
JOptionPane.showMessageDialog(null,"It works!");
System.exit(0);
}
}

Thank you.
   

Login/Register to Answer

Related Questions