2

I'm on the Eclipse program for Java developers, and for some reason, Eclipse doesn't recognize import javax.swing.JOptionPane when creating a new class.

If you attempt to make a new class and have the code imported automatically, nothing pops up

Java Error

In fact, nothing remotely related to javax.swing pops up. Any ideas on what's going on? I removed the JRE system library and re-added it again. But that didn't work.

Community
  • 1
  • 1
Crescendo
  • 105
  • 1
  • 10
  • A quick [google](https://www.google.com.au/search?client=safari&rls=en&dcr=0&q=eclipse+javax.swing&oq=eclipse+javax.swing&gs_l=psy-ab.3...0.0.0.12080.0.0.0.0.0.0.0.0..0.0....0...1..64.psy-ab..0.0.0....0.X2AlhOCgVQ4) brings up a few possible remedies - Have you tried any? If so, which ones didn't work for you? In what ways is your problem "seemingly" different from the others who had similar problems? – MadProgrammer Sep 27 '17 at 03:19
  • Based on your error message, [this previous answer look promising](https://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar) – MadProgrammer Sep 27 '17 at 03:21
  • You type JOptionPane in Choose a Type Textbox and then related package will show below. After that choose the below package. – Myo Sep 27 '17 at 03:51
  • @MadProgrammer That’s what I meant when I said “remove JRE library and re-add it.” – Crescendo Sep 27 '17 at 03:53
  • @Myo Typing javax.swing.JOptionPane should produce the same thing as typing JOptionPane. Also, simply typing JOptionPane doesn’t work either. – Crescendo Sep 27 '17 at 03:55
  • @MadProgrammer Replying to your first comment, I saw the question about https://stackoverflow.com/questions/14181142/eclipse-doesnt-find-javax-swing. I followed every step and it matches up. But JOptionPane still isn’t showing. – Crescendo Sep 27 '17 at 03:56
  • Have you tried to create a new fresh workspace and project to see if it occurs there? It shouldn't, of course, but I recall having instances where the metadata of a workspace or project seemed to be messed up. – M. le Rutte Oct 01 '17 at 14:28
  • @M.leRutte Yup, I just tried creating a new workspace. The same error occurs. – Crescendo Oct 01 '17 at 22:14
  • @Crescendo Could you add the details of 1. the jre/jdk that you're configuring. 2. `java -version` on your machine 3. eclipse version that you're using. – Naman Oct 02 '17 at 07:50
  • Also, could you state, how is this is not a duplicate of https://stackoverflow.com/questions/14181142/eclipse-doesnt-find-javax-swing already? – Naman Oct 02 '17 at 08:03
  • @nullpointer I fixed the problem. Kind of a dumb mistake too – Crescendo Oct 03 '17 at 03:18
  • @Crescendo shall this be marked as Off-Topic in that case? – Naman Oct 03 '17 at 03:25
  • Are type filters (_Window > Preferences: Java > Appearance > Type Filters_) set? If no, does rebuild the Java index (in _Window > Preferences: Java_ click the _Rebuild Index_ button) fix the problem? – howlger Oct 03 '17 at 07:54
  • 1
    @howlger I fixed it, I just uninstalled jdk and eclipse, and reinstalled it. – Crescendo Oct 03 '17 at 16:44

1 Answers1

1

Here are some things that could be causing a problem:

  1. Make sure you have a JDK installed and selected in eclipse

    Window > Preferences > Java > Installed JREs
    
  2. Make sure it’s in your build path

    Project > Properties > Java Build Path > Libraries
    

    One of the Libraries should be something along the lines of “JRE System Library [JDK9]”. If there isn’t one, add it with:

    Add Library > JRE System Library
    
  3. Your project should be a Java project

    Project > Properties > Builders
    

Should have a “Java Builder” entry.

After doing all that, rebuild your project with Project > Clean then select your project. If none of that works, completely uninstall Java, reinstall the JDK and JRE then repeat steps 1-3. Source.

Steampunkery
  • 3,839
  • 2
  • 19
  • 28
  • I deleted Eclipse, and redownloaded it last night. It turns out that if you manually type in `import javax.swing.JOptionPane`, a red box on the right appears. But the program still runs. Is there a way to fix that part? – Crescendo Oct 01 '17 at 22:52
  • Hmm. Seems like an eclipse glitch. What JDK version are you using, and what eclipse version? – Steampunkery Oct 02 '17 at 01:25
  • Nevermind, I found out what was wrong with eclipse. Not sure what, but I just uninstalled everything, reinstalled everything, and installed Eclipse into the C: folder. – Crescendo Oct 03 '17 at 03:16
  • Does this mean I get the bounty? – Steampunkery Oct 03 '17 at 13:38