8

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;
iswinky
  • 1,951
  • 3
  • 16
  • 47
  • Try to follow [this video](http://www.youtube.com/watch?v=CXO0aT6rXTQ). That was the one I used to setup my first libgdx project. The unused import should appear grayed out in the source code by the IDE. – dawez Oct 21 '14 at 10:28
  • Be sure also that you use in the running Run/Debug configuration: Use classpath of module: desktop. – dawez Oct 21 '14 at 10:38
  • Please try again to recreate the project following the steps in the video I suggested earlier. – dawez Oct 22 '14 at 07:36
  • @dawez when I've got time I'll give it a go and let you know! Cheers – iswinky Oct 22 '14 at 08:34
  • The video posted above didnt help...but the answer to this SO question did: http://stackoverflow.com/a/34154999/324444 – Tim Boland Dec 29 '15 at 23:13

2 Answers2

6

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.

steamdragon
  • 1,052
  • 13
  • 15
1

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

Tactical Catgirl
  • 419
  • 4
  • 10