Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGdx Desktop launcher error: main class not found

After creating a new LibGdx project using the setup.jar file. I have followed the instructions for configuring my new application using IntelliJ and launching the desktop application. But I'm getting the following error:

Exception in thread "main" java.lang.ClassNotFoundException: com.mygdx.game.desktop.DesktopLauncher
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)

DesktopLauncher.java:

package com.mygdx.game.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.MyGdxGame;

public class DesktopLauncher {
    public static void main (String[] arg) {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        new LwjglApplication(new MyGdxGame(), config);
    }
}

The IDE is saying "unused imports" suggested it can't find them at all.

Update:

11:54:56 Gradle 'newgame' project refresh failed:
         Cause: org.gradle.plugins.ide.internal.IdeDependenciesExtractor.extractRepoFileDependencies(Lorg/gradle/api/artifacts/ConfigurationContainer;Ljava/util/Collection;Ljava/util/Collection;ZZ)Ljava/util/List;
like image 595
iswinky Avatar asked Oct 21 '14 08:10

iswinky


2 Answers

This fixed it for me:

On the Desktop "Run/Debug" configuration, select the appropriate JRE directory. For me, it was: C:\Program Files\Java\jre1.8.0_73.

like image 145
zentia Avatar answered Oct 22 '22 19:10

zentia


Had the same problem with freshly-generated gdx project. Solved by adding desktop:build task to run before launch.

like image 34
Tactical Catgirl Avatar answered Oct 22 '22 20:10

Tactical Catgirl