When I try and import the AWT package in eclipse by doing "import java.awt.*;" at the beginning of my code it comes up with an error that "The package java.awt is not accessible." java.util seems to work fine, but the awt package doesn't. I'm not sure what I need to do to make it "accessible".
Asked
Active
Viewed 8.0k times
10
-
rebuild the project, or clean the project or look [here](https://stackoverflow.com/questions/13705087/the-import-java-awt-cannot-be-resolved-and-cannot-be-resolved-to-a-typ) – madhepurian Sep 28 '19 at 20:15
-
Alright I'll try that thanks – EvilBob73 Sep 28 '19 at 20:19
-
Hmm, none of that seems to work – EvilBob73 Sep 28 '19 at 21:00
-
7Finally got it to work by adding "requires java.desktop;" into "module-info.java". More information can be found here: https://stackoverflow.com/questions/51503140/the-import-java-awt-cannot-be-resolved/51504409 – EvilBob73 Sep 28 '19 at 21:19
-
Late here, but just wanted to say that adding the "requires java.desktop" in "module-info.java" worked for me. Thanks! – hrmello May 25 '21 at 13:34
1 Answers
8
You can fix it by following the following steps:
Go to: Project -> Properties -> Libraries -> Add Library -> Execution Environment
Select the drop down list and then choose "javaSE-1.7"
That solved the problem for me!

Adrian Mole
- 49,934
- 160
- 51
- 83

B97
- 97
- 1
- 2
-
9That's a terrible solution for, especially as it was posted in 2020. That's not solving the problem that's avoiding it all together. Also, this will only work for those who still have JavaSE-1.7. – Andrew S Mar 24 '21 at 23:42