Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Error message when using JOptionPane

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default 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?

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default 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.

  6. #6
    Junior Member
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default 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.

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error message when using JOptionPane

    The fix you gave me last time worked could you send it again please

Similar Threads

  1. How to display error message box
    By jasonxman in forum What's Wrong With My Code?
    Replies: 11
    Last Post: August 21st, 2011, 02:47 PM
  2. [SOLVED] Help making an error message.
    By Lost_Secret in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 1st, 2011, 04:48 PM
  3. Strange error message
    By javapenguin in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 11th, 2011, 02:03 PM
  4. an error message while runnung java
    By sravan_kumar343 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 25th, 2010, 10:19 AM
  5. help with a error message
    By JavaNoob82 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2010, 02:56 PM