[英]Main class not found in project IntelliJ IDEA: Java Application
IntelliJ 在我的 Java 應用程序項目中找不到主類。 該項目是從 git 存儲庫克隆的,因此沒有運行配置。 我轉到編輯配置,添加一個新的應用程序模板,轉到主類:它說“在項目中找不到匹配項”。
因此,手動搜索層次結構,我找到了包含 main 函數的 .java 文件,但它不會將其作為主類接受。 我已經粘貼了下面的文件以證明它具有正確的主要功能。
public class AdvanceWarsGameHandler implements IGame
{
private Image mImage;
private String mTitle;
public AdvanceWarsGameHandler()
{
mTitle = "Advance Wars Game";
mImage = new Image("/OffBrandCerealOopsAllCarries2-01.png");
}
//Game logic unrelated to graphics goes here
@Override
public void update(Game game, float deltaTime)
{
}
//Update, but for graphics
@Override
public void render(Game game, Renderer renderer)
{
renderer.drawImage(mImage, game.getInput().getMouseX(), game.getInput().getMouseY());
}
public static void main(final String args[])
{
//Creating and starting an instance of AdvanceWarsGameHandler
AdvanceWarsGameHandler advancewars = new AdvanceWarsGameHandler();
Game myGame = new Game(advancewars);
myGame.start();
}
public String getTitle()
{
return mTitle;
}
}
所以問題是,為什么 IntelliJ 項目無法識別此文件中的 main 函數,或者 IntelliJ 尋找什么作為應用程序的“主類”?
好的,希望這個答案能幫助不熟悉 IntelliJ IDEA 的其他人。
解決方案分為兩部分
第 1 部分:缺少編譯目錄。
由於我沒有從 new 創建項目,而是克隆了一個 Git 存儲庫,因此沒有設置默認的編譯目錄。
要在 IntelliJ IDEA 中訪問它,請轉到文件->項目結構->項目並設置“項目編譯器輸出”,以便項目可以實際編譯。
第 2 部分:設置模塊
原始項目是在帶有包的 Eclipse 中創建的。 為了讓這些包在 IntelliJ 中工作,我必須轉到“項目結構”菜單的“模塊”選項卡,並將我的 src 和 res 文件夾設置為源和資源文件夾。 這允許 IntelliJ 在我的類中找到 main() 函數並且程序按預期運行。
這解決了我的問題,但如果你們中的任何一個 IntelliJ 用戶可以看到我為使其正常工作所做的任何事情,請發表評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.