問題描述
libgdx ‑ Intellij 類未找到異常? (libgdx ‑ Intellij class not found exception?)
我是第一次使用 intellij
,但我無法運行任何程序。它構建時沒有任何錯誤或警告,但是當我運行時,它會拋出 class not found 異常
。我已經盡我所能
- 在 stack‑overflow 上搜索。
- 我已經檢查了模塊設置下的源文件夾。
- 我'我也檢查了運行配置
但沒有運氣。
錯誤:
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)
類源:
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);
}
}
參考解法
方法 1:
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.
方法 2:
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."
(by conversation.16、conversation.16、disperse)