5

I am using intellij for the first time and I haven't been able to run any program. It builds without any errors or warnings but when I run, It throws the class not found exception. I have tried everything I could

  • Search on stack-overflow.
  • I've checked the source folder under the module setup.
  • I've checked the run configurations as well

but no luck.

Error:

Exception in thread "main" java.lang.ClassNotFoundException: com.nectarmicrosystems.libgdx.learning.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)

the class source:

package com.nectarmicrosystems.libgdx.learning.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.nectarmicrosystems.libgdx.learning.MyGdxGame;

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

dependencies

source structure

conversation.16
  • 426
  • 2
  • 13
  • 28

2 Answers2

11

Thanks to every one that helped, I found the solution. basically the DesktopLauncher class was not getting compiled, so I ran the task through gradle this way:

look for the Gradle panel in the IDE, open desktop -> Tasks -> other and then double click on run.

you only need to do this the first time.

conversation.16
  • 426
  • 2
  • 13
  • 28
4

For people who are experiencing this problem, try selecting "desktop_main" in the "Use classpath of module:" drop-down list.

I was getting this error when I selected "desktop" as the module but the error went away when I selected "desktop_main."

disperse
  • 1,216
  • 10
  • 22