vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

VSCode error javax.swing does not exist

Open MuhammadimYusoff opened this issue 5 years ago • 12 comments

Environment
  • Operating System: MacOS Catalina
  • JDK version: JAVA 8 Update 241
  • Visual Studio Code version: Version: 1.42.1
  • Java extension version: 0.8.1
Steps To Reproduce

I import as follows:-

import javax.swing.; // Error 'package javax.swing does not exist' import java.util.ArrayList; import java.io.; import java.util.StringTokenizer;

Causing error on 'JOptionPane' on every java files.

Current Result
  1. The IDE an Error on the 'import javax.swing.*' as 'package is not exist'
  2. Error on every 'JOptionPane' lines.
Additional Informations

Extension List:- Java Extension Pack Advance New File Better Comments Bracket Pair Colourizer Checkstyle for JAVA Code Runner Color Highlight Material Theme Error Lens GetHelp IntelliJ Keybindings Settings Sync Smart Multi Cursor Terminal Wakatime

MuhammadimYusoff avatar Mar 01 '20 17:03 MuhammadimYusoff

@MuhammadimYusoff you may want to take a look at https://github.com/redhat-developer/vscode-java/issues/1147#issuecomment-554529618

snjeza avatar Mar 01 '20 18:03 snjeza

I have tried it but also failed, the 'import javax.swing.*' line still have error.

I have saved the settings.json, quit VSCode and open up VSCode again but the error still there.

BTW is 'javax.swing.' and 'java.awt.' both of them GUI related libraries? Other threads says about conflicting libraries but I am not sure about this one.

MuhammadimYusoff avatar Mar 01 '20 19:03 MuhammadimYusoff

I can't reproduce the issue. Could you attach a project example?

snjeza avatar Mar 01 '20 20:03 snjeza

https://pastebin.com/Nr6gkfda

I have place it on above link for you. I also have place the comment at first line.

MuhammadimYusoff avatar Mar 02 '20 04:03 MuhammadimYusoff

@snjeza I think my system does not automatically set PATH for JVM, as per se the problem persist.

but as I am looking at my terminal nothing mentioned about JVM is not setup or related to it, but as I setup the PATH, the error still there, but at runtime the code running fine after I clean up the JAVA cache and all.

MuhammadimYusoff avatar Mar 02 '20 05:03 MuhammadimYusoff

I have the same problem. However, JOptionPane still works though.

Dameonn avatar Oct 06 '20 03:10 Dameonn

Do I need to add javax.swing jars to classpath?

patricechaula avatar Oct 13 '20 13:10 patricechaula

I am having the same problem. Any solution(s) ?

anserwaseem avatar Mar 30 '21 08:03 anserwaseem

in vscode: go to settings, search for java , scroll down to "Java › Completion: Favorite Static Members" click in "edit in settings.json" and delete this peace of code(or comment it in case it doesn't work) //"java.addExports": [ //"javax.swing", //"java.awt" //],

obahii avatar May 14 '22 00:05 obahii

----------SOLUTION----------

Go to settings.json and add the following lines:

"java.addExports": [ "javax.swing", "java.awt" ],

Then, restart Visual Studio Code !!

billtsol avatar Nov 17 '22 21:11 billtsol

----------SOLUTIONS----------

Go to settings.json and add this:

"java.addExports": [ "javax.swing", "java.awt" ],

restart the vscode !!

This work perfectly . thanks a lot

Pasetop5 avatar May 01 '24 16:05 Pasetop5

----------SOLUTION----------

Go to settings.json and add the following lines:

"java.addExports": [ "javax.swing", "java.awt" ],

Then, restart Visual Studio Code !!

It works for me, Thanks

phurku avatar May 23 '24 09:05 phurku

----------SOLUTION----------

Go to settings.json and add the following lines:

"java.addExports": [ "javax.swing", "java.awt" ],

Then, restart Visual Studio Code !!

It work for me too, Thanks !

heroldg avatar Jan 04 '25 17:01 heroldg