1. 程式人生 > >Access restriction: The type is not accessible due to restriction on required library問題處理

Access restriction: The type is not accessible due to restriction on required library問題處理

在做Java時,遇到了個小問題,在Import 包資源時出現:

       Access restriction: The type XXX is not accessible due to restriction on required library 錯誤!如下圖:


經過查證 原來是:JDK下如rt.jar包中某些資源預設是不讓用的。這是其Access規則,在網上看到很多帖子都說把Warning的驗證禁用掉,個人感覺這不是好的辦法。

經過一些資料發現修改專案檔案的Access rules可以解決這一問題:

選擇工程專案右鍵->Properties->java builder path->Libraries,點選JRE System Library裡面的Access rules,增加或者是Edit Resolution

為accessible的選項,在Rule Pattern中寫上所需要的包資源路徑,如下圖所示:



有關Rule Pattern的輸入,因為我這裡是在Import JDK下rt.jar中的sun包下某個類時出現錯誤,所以我這就填寫sun/**

如果是其他的包,則填寫相應的即可!點選確定後,即可成功解決上面的問題。