Search code examples
javalibgdx

Can't run libgdx project as desktop application


I'm using intellij idea ide and when I try to run my libgdx project as desktop application I get this message.

Exception in thread "main" java.lang.ClassNotFoundException: com.nivekbryan.labirint.desktop.DesktopLauncher
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)

Solution

  • I had a same problem so i fixed with this solution. Basically compiler is not getting DesktopLauncher class, so you need to run the task through gradle this way:

    Look for the Gradle panel in the IDE,

    1. Hit Shift twice, type "Gradle" to open the Gradle projects pane
    2. Hit the "Refresh all Gradle projects" button if nothing is showing up
    3. Expand :desktop > Tasks > other
    4. Double-click "run"

    you only need to do this the first time for launch DesktopLauncher class after that you will not get this exception.

    I hope it will work for you, cheers.