简体   繁体   中英

VS Code Homebrew Java SDK Creates Project Errors on Default Components (Main, Double, String etc.)

Environment: I had a series of unexplainable errors on a macOS system running macOS Big Sur and while I was trying to run my application using this guide from the official VS Code website .

Issue: Every time I opened a certainly working project in VS Code (tested in the IntelliJ IDE), it was full of errors like String is not a known class or main method not defined in class etc.

Understanding the Problem: I quickly figured out that the issue has to do with the JDK being misconfigured, and now I had to figure out if the issue was in VS Code or Homebrew. The issue I suspected lied in VS Code and originated from my choice to use a JDK downloaded and managed by the Homebrew package manager . After verifying my Homebrew installation of the given cask and making sure system paths were set correctly, I was certain of the previously made assumption.

Solution:

  1. Open the folder in VS Code
  2. Collapse the Java Projects Tab in the Explorer menu (make sure you have the [java language package extension][3] downloaded)
  3. Click the three dots icon '...' which appears when you hover over the Java Projects area with your mouse.
  4. Select 'Configure Java Runtime'. A new tab will open.
  5. On the Java Version column, select the pencil icon.
  6. Open the dropdown menu and select a Java Version from the Java Virtual Machines folder instead of opt/Homebrew directories (it may be the same JDK from Homebrew using an alias, but VS Code expects the Virtual Machine folder and that is my theory in why this works).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM