Eclipse cant find the import javax.swing.JOptionPane
Where is it located and how can i include it?
import javax.swing.JOptionPane;
Eclipse cant find the import javax.swing.JOptionPane
Where is it located and how can i include it?
import javax.swing.JOptionPane;
There must be an installed (and selected) JDK in Eclipse:
Window > Preferences > Java > Installed JREs
The project must be configured to use that JDK:
Project > Properties > Java Build Path > Libraries
there should be an entry like "JRE System Library [JDK7]" in the list. If not press:
Add Library... > JRE System Library
The project should have been created as a "Java Project":
Project > Properties > Builders
should include "Java Builder"
The accepted answer did not work for me.
This is how I solved it:
Right-Click on your project, select Properties
Go to Java Build Path
Click Libraries
, then Add Library ...
Select JRE System Library
Click on Execution environment
and select JavaSE-1.7
or JavaSE-1.8
Click Finish
, then Apply and Close
.
Try to Update the execution environment under system library to JavaSE-1.7 or JavaSE-1.8 in eclipse. To update the step below can be followed:
> Right-click on the project
> Select properties
> Java build path
> Library > Add Library > Add JRE SYSTEM Library
> Execution Environment
> Select JavaSE-1.7 or JavaSE-1.8
> Finish
In the beginning when you start to create a new java project just don't click "finish" or "next" directly. But go to the JavaSE version text input at the middle of the form and choose JavaSE 1.6 or 1.7 or 1.8, then click next -> finish. Then it with parse and work.
One of my Eclipse projects couldn't find javax.swing The other projects had no problem, the configurations were identical and default.
I found this video on YoutubeVideo of changing the JRE I changed my JRE to 1.7 like suggested in video and it worked. Then, because I thought it was a bug, I changed it back to JRE 17 and it still worked.