Skip to content

Troubleshooting

If you're having issues with Java, VS Code, running your files, or running unit tests, try the steps below and make sure you have everything correct!

Clean Java Workspace

First, try cleaning the Java workspace. This clears your projects and restarts VS Code.

Open the Command Palette with one of the following shortcuts:

  • F1
  • Ctrl+Shift+P   (PC)
  • Cmd+Shift+P   (Mac)

Search for clean java. You'll want to select the Java: Clean Java Language Server Workspace option:

Clean Java

Next, in the lower-right corner, click Reload and delete:

Reload and delete

Common Issues

  1. Make sure the CS159 folder is open in VS Code

    • In VS Code, use the top menu to go to File > Open Folder... and then select the CS159 folder that you downloaded in Install Java and VS Code.
    • You should see a single CS159 folder at the top of the explorer pane:

      CS159 Folder

    • There should be four folders underneath, .vscode, bin, lib, and src.

  2. Make sure your code is placed in appropriate folders under the src folder

    • Homework must go in individual hw01, hw02, etc. folders inside the hws folder
    • Labs must go in individual folders under labs, etc.
  3. Make sure your package statement matches the folder structure

    • e.g., if you have ExactChange.java in src/hws/hw2, the package must be hws.hw2.

      Package statement matches folder structure

    • Usually VS Code automatically inserts the package statement for you, but if you move files around, the package statement could be incorrect.

  4. If you are unable to run a file, make sure that it is something you can run!

    Select main file

    • You can't "run" a file that doesn't contain a main() method.
    • Don't create a main method unless the assignment asks for it. (Gradescope may not be happy if you do so.)
    • Instead, you should be running your unit tests to check if your code works.
  5. If you get an error saying that the Update jacoco.xml task failed, or you are unable to display coverage:

    • Please check your Java version and make sure JDK 21 is installed.

Uninstalling JDK

Check the version of Java you're on by opening a terminal or command prompt and running the command java -version.

Java version

If this shows a major version of 21 (unlike in the screenshot above), then you're good to go!

If this shows any other version (like 17), then you will need to uninstall the current JDK and install version 21.

  • On Windows:

    • In your Start Menu, open "Add or remove programs" or "Apps and features", then search for Temurin, JDK, or Java.

      Uninstalling JDK on Windows

    • Uninstall anything that is not version 21.

  • On Mac:

    • Open the Finder, then go to Macintosh HD > Library > Java > JavaVirtualMachines.
    • Delete any folders that are not version 21 (like temurin-17.jdk).

Next, follow the steps in Install Java and VS Code to install version 21 of the JDK.

Important!

Afterwards, open VS Code and clean the Java workspace. You may have to wait a while for VS Code to re-open your projects and work with the new JDK version.