【Java】解决Acces restriction: The type X is not accessible due to restriction on required library 的解决方法

新手初学java,照着书敲的代码都会报错,实在是郁闷。在度娘上面找到了解决方法,先记录以飨读者。


import javax.swing.JOptionPane;  // program uses JOptionPane

public class chenrenwangaijiexi {
   public static void main( String args[] )
   {
      String firstNumber; 
      String secondNumber;
      int number1=0;
      int number2=0;       
      int product=0;           
      firstNumber = JOptionPane.showInputDialog( "输入乘数" );
      secondNumber =JOptionPane.showInputDialog( "输入被乘数" );
      try {
          number1 = Integer.parseInt( firstNumber );
          number2 = Integer.parseInt( secondNumber );
          product = number1*number2;
          JOptionPane.showMessageDialog( null,number1+"*"+number2+"="+product ,
              "结果", JOptionPane.PLAIN_MESSAGE );
       } 
      catch(NumberFormatException ex)  {
            JOptionPane.showMessageDialog( null,
         "你在输入对话框中没有输入整数值","消息", JOptionPane.PLAIN_MESSAGE );
      System.exit( 0 );
       }
          product = number1 * number2;
          System.exit( 0 );   // terminate application with window
     } // end method main
} // end class Addition




解决办法:在Build Path里面把JRE System Library移除后重新添加进去,问题解决

你可能感兴趣的:(java)