Skip to content

VSCode error javax.swing does not exist #1311

Closed

Description

@MuhammadimYusoff
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

Activity

  1. snjeza commented on Mar 1, 2020

    @snjeza
    Collaborator

    @MuhammadimYusoff you may want to take a look at #1147 (comment)

  2. MuhammadimYusoff commented on Mar 1, 2020

    @MuhammadimYusoff
    Author

    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.

  3. snjeza commented on Mar 1, 2020

    @snjeza
    Collaborator

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

  4. MuhammadimYusoff commented on Mar 2, 2020

    @MuhammadimYusoff
    Author

    https://pastebin.com/Nr6gkfda

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

  5. MuhammadimYusoff commented on Mar 2, 2020

    @MuhammadimYusoff
    Author

    @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.

  6. Dameonn commented on Oct 6, 2020

    @Dameonn

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

  7. patricechaula commented on Oct 13, 2020

    @patricechaula

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

  8. anserwaseem commented on Mar 30, 2021

    @anserwaseem

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

  9. obahii commented on May 14, 2022

    @obahii

    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"
    //],

  10. billtsol commented on Nov 17, 2022

    @billtsol

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

    Go to settings.json and add the following lines:

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

    Then, restart Visual Studio Code !!

  11. Pasetop5 commented on May 1, 2024

    @Pasetop5

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

    Go to settings.json and add this:

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

    restart the vscode !!

    This work perfectly . thanks a lot

  12. phurku commented on May 23, 2024

    @phurku

    ----------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

  13. heroldg commented on Jan 4, 2025

    @heroldg

    ----------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 !

  14. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    10. ----------SOLUTION----------
    Go to settings.json and add the following lines:
    "java.addExports": [
    "javax.swing",
    "java.awt"
    ],
    Then, restart Visual Studio Code !!

    This workaround seems to have fixed it for everyone, and is in fact the right thing to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions