4

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)
Kevin Bryan
  • 1,846
  • 2
  • 22
  • 45

1 Answers1

6

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.

Piyush Gupta
  • 2,181
  • 3
  • 13
  • 28
  • where? i can' t find it, do you mean open desktop module? but there is not "Tasks" inside it. – Kevin Bryan Feb 22 '16 at 05:59
  • One more thing, when I run using gradle it works but when I use desktop it doesn't update or follow the new codes. – Kevin Bryan Feb 22 '16 at 07:33
  • Did you set Project compiler output?...refer this http://stackoverflow.com/questions/22105264/running-tests-on-intellij-class-not-found – Piyush Gupta Feb 22 '16 at 08:32
  • I guess Android studio has changed too much since then. It's not possible to do 'Expand :desktop > Tasks > other'... – Hasen Dec 02 '19 at 05:54
  • This works ! Thank you - just follow his instructions ... I'm using the latest Android studio and it worked a charm. – Le Roi Beukes Jun 11 '20 at 08:46
  • In android studio 4.1.1, you can do this using gradle pane window. you can access gradle pane through view menu > tool windows > gradle – Joseph Bani Jan 10 '21 at 16:23