You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

libGDX搭建Mario项目遇错求助:Java版本识别失败及类找不到问题

Hey there! Let's work through those two issues you're hitting with your libGDX Mario project—since you're only two months into Java and following a 2015 tutorial, version mismatches and configuration hiccups are totally expected, so don't stress!

问题1:无法从'9.0.1'确定Java版本

This error happens because the 2015-era libGDX tooling (like Gradle) wasn't built to recognize newer Java version number formats (Java 9+ switched from the old 1.x naming to just x). Here are two solid fixes:

  • Downgrade to Java 8: This is the most straightforward fix, since Java 8 was the standard when the tutorial was released, and early libGDX versions work flawlessly with it. Install Java 8, then go into your IDE's project settings and set the SDK to Java 8 for all modules in your project.
  • Update Gradle config (if you want to keep Java 9+): If you'd rather stick with your current Java version, tweak your project's root build.gradle file:
    allprojects {
        apply plugin: "java"
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    
    Also, update your Gradle wrapper to a version that supports newer Java versions. Open gradle/wrapper/gradle-wrapper.properties and change the distribution URL to:
    distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
    
    This version of Gradle works with Java 8 through 11, which should cover your Java 9.0.1 setup.
问题2:模块'PMario'中未找到类'com.mygdx.mario.desktop.DesktopLauncher'

This usually boils down to a misconfigured project structure or IDE sync issue. Try these steps:

  • Double-check your file structure: Make sure DesktopLauncher.java is located exactly at src/desktop/java/com/mygdx/mario/desktop/DesktopLauncher.java. Also verify the package declaration at the top of the file is package com.mygdx.mario.desktop;—Java is case-sensitive, so even a tiny typo (like Desktoplauncher instead of DesktopLauncher) will break this.
  • Re-sync your project with Gradle: If you're using IntelliJ or Eclipse, use the IDE's Gradle sync feature (in IntelliJ, it's the elephant icon in the top-right). Sometimes IDEs fail to pick up new classes or module configurations until you sync.
  • Verify the desktop module's build.gradle: Open the desktop/build.gradle file and make sure the source sets are correctly pointing to your code:
    sourceSets.main.java.srcDirs = ["src/desktop/java/"]
    
  • Run a Gradle compile command: Open your terminal, navigate to your project root, and run ./gradlew desktop:compileJava (on Windows, use gradlew.bat desktop:compileJava). This will show you any actual compilation errors that might be hiding behind the "class not found" message—maybe a missing import or syntax error that's preventing the class from being built.

You're doing great for only two months into Java—these setup kinks are just part of learning how game dev tools work. Stick with it, and you'll have your Mario clone up and running in no time!

内容的提问来源于stack exchange,提问作者Signka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:25:46