1. 程式人生 > >Access restriction: The type 'JPEGCodec' is not API

Access restriction: The type 'JPEGCodec' is not API

ssi cat jpeg .net jre warning 今天 req tail

問題

今天導入項目時Eclipse報錯如下:

Access restriction: The type ‘JPEGCodec‘ is not API (restriction on required library ‘C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar‘)

第一次遇到這種錯誤,百度了下,原來是因為Eclipse默認把訪問受限的API設置成了Error級別,所以才會編譯報錯。

解決方法

方法一(推薦)

直接將項目的JRE給remove掉,然後再重新將JRE添加到項目中,操作如下:

  1. 右鍵項目,選擇Properties -> Java Build Path -> Libraries -> 選中JRE System Library [jdkxxxx] -> 選擇Remove
  2. 接著選擇Add Librariy...,重新加入JRE

方法二

修改Eclipse中關於訪問受限的API的編譯級別:

Window -> Preferences -> Java -> Compiler -> Errors/Warnings,選擇Deprecated and restricted API,將其中的Forbidden reference(access rules)的級別選為Warning。

參考鏈接

  • 解決辦法:Access restriction: The type JPEGImageEncoder is not accessible due to restriction

Access restriction: The type 'JPEGCodec' is not API