Error message when using JOptionPane
I am a beginner at Java programming. I wrote these lines of code using JOptionPane but continues to obtain an error message
import javax.swing.JOptionPane;
public class JOpt
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "Message" , JOptionPane.INFORMATION_MESSAGE);
}
}
Error message
Access restriction: The type JOptionPane is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre7\lib\rt.jar
Access restriction: The field INFORMATION_MESSAGE from the type JOptionPane is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre7\lib\rt.jar
at JOpt.main(JOpt.java:10)
What could the problem be
Is something wrong with my compiler
Re: Error message when using JOptionPane
Nothing wrong with compiler.
When using this type of dialog box you need to pass in the message String and also the title String.
try some thing like:
JOptionPane.showMessageDialog(null, "Message","Information Message" , JOptionPane.INFORMATION_MESSAGE);
you will see the second message up on the title bar.
hope this helps.
Still having problem with JOptionPane
I got a reply about my problem and replied but I am hot sure the reply was sent
Thanks to Dave
Below I have made the change
import javax.swing.JOptionPane;
public class JOpt
{
public static void main(String[] args)
{
//JOptionPane.showMessageDialog(null, "Message" , JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "Message","Information Message" , JOptionPane.INFORMATION_MESSAGE);
}
}
The error message is
Access restriction: The type JOptionPane is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre7\lib\rt.jar
Access restriction: The field INFORMATION_MESSAGE from the type JOptionPane is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre7\lib\rt.jar
at JOpt.main(JOpt.java:12)
What does the error message mean
Re: Error message when using JOptionPane
I guess i was wrong there seems to be something wrong with compiler. What text editor are you using?
Can you compile any code, or is it just with GUI stuff your having a problem?
Re: Error message when using JOptionPane
It works for me, so I would say something is up with your JRE runtime jar. I know there are restrictions on tampering with it that can produce errors. Some have tried adding other classes to the runtime.
Try reinstalling the JRE.
Re: Error message when using JOptionPane
It compiles other stuff but not JOptionPane
Please send me the changes that made it work, again. I did not copy the note and the same thing has happened again. Are you saying that I may have to download Eclipse again. Which version do you recommend please send me a link
Re: Error message when using JOptionPane
I would reinstall Java and see if that makes a difference. Take advantage of the security update in release 13.
Re: Error message when using JOptionPane
The fix you gave me last time worked could you send it again please