昨天我上传了一些项目到我的github,它编译得很好,今天我尝试从其他计算机克隆它,我关注了this guide ,但是当我尝试运行代码时,我得到:
Error: Could not find or load main class gui.MainScreen Caused by: java.lang.ClassNotFoundException: gui.MainScreen
我尝试这样做 this post ,但我不明白他的回答,有人可以发布更清晰的答案吗?屏幕截图会有很大帮助。
代码大致如下:
package gui;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainScreen extends JFrame
{
public MainScreen() throws IOException
{
....
this.pack();
this.setVisible(true);
}
}
public static void main(String[] args)
{
//avoid blocking the main thread
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
try {
new MainScreen();
} catch (IOException e) {
e.printStackTrace();
};
}
});
}
}
最佳答案
您需要将主类放在单独的文件中。从您的屏幕截图来看,MainScreen 类中似乎有主类。您可以将包含主类的文件命名为您想要的任何名称(但不要将其命名为 main,以避免混淆)。
如果您的主类确实位于单独的文件中,请在 Eclipse 中克隆项目后设置主类。检查此链接 How to set the main class in Eclipse 。我不确定您克隆的 github 项目中是否存在该信息。转到“运行配置”并设置完全限定的主类名称,如链接所示,您还可以搜索整个项目,这将为您提供主类。设置它然后运行该项目。希望这会起作用。
关于从 github eclipse 克隆后出现 java.lang.ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56642205/