IntelliJ中JavaFX无法打开窗口、运行异常问题求助
Hey fellow hobby dev! That exit code (-1073740791, right?) is super common when setting up JavaFX in IntelliJ— I’ve fought this exact issue a few times. Let’s break down the fixes that usually get it working:
1. Match Your JDK and JavaFX Versions
This is the #1 culprit. JavaFX is tightly linked to JDK versions—if you’re using JDK 17, you need JavaFX 17; JDK 21 needs JavaFX 21, etc. Version mismatches will crash the app before it even loads.
- To verify: Go to
File > Project Structure > Projectto check your JDK version, then switch to theLibrariestab to confirm your JavaFX SDK version. If they don’t align, grab the matching JavaFX release.
2. Fix Your Run Configuration
IntelliJ’s pre-generated JavaFX project sometimes skips critical VM arguments. Here’s how to fix it:
- Open
Run > Edit Configurations - Select your JavaFX application entry
- In the
VM optionsfield, paste a line like this (replace the path with your actual JavaFX SDK lib folder):--module-path "C:/path/to/javafx-sdk-17/lib" --add-modules javafx.controls,javafx.fxml - Double-check that the
Main classfield points to your class that extendsApplication(the one with thestart()method).
3. Switch to Classpath Instead of Module Path (Temporary Quick Fix)
Sometimes IntelliJ’s module path handling glitches out. Try this to bypass it:
- In the run configuration window, click the
Modify optionsdropdown - Uncheck
Use module pathand checkUse classpath instead - Hit run—this often resolves the crash instantly, though it’s not a long-term fix if you’re using modules.
4. Update IntelliJ and JavaFX Plugins
Outdated IDE or plugins can cause weird compatibility bugs:
- Go to
File > Settings > Pluginsand check for updates to the JavaFX Plugin - Update IntelliJ itself via
Help > Check for Updates—newer versions often fix JavaFX setup quirks.
5. Reinstall JavaFX SDK
If nothing else works, your JavaFX SDK might be corrupted:
- Delete the existing SDK from your system
- Download a fresh, official copy of the JavaFX SDK
- Re-add it to your project in
File > Project Structure > Libraries
Pro Tip: If you haven’t already, consider using Maven or Gradle to manage your JavaFX dependencies. Their official JavaFX plugins handle module paths and versioning automatically, so you won’t have to mess with these setup issues again.
内容的提问来源于stack exchange,提问作者SimmensK

