我是Java初学者,正在尝试使用IntelliJ运行我的代码,我刚刚将它安装为JDK 1.7的IDE。下面这段代码甚至不能编译,并不断给我错误:

Error: Could not find or load main class libTest

Code

import java.lang.Integer;
import java.lang.String;
import java.lang.System;
import java.util.*;

class book {

    private String name = "trial";
    private int bookCode=1;
    private int issued=0;

     public void Issue(){
         if(issued==0) {
             issued=1;
             System.out.println("You have succesfully issued the book");
         }
         else {
             System.out.println("The book is already issued. Please contact the librarian for further details");
         }
    }

    public int checkCode() {
        return bookCode;
    }

    String readName() {
        return name;
    }

    public void setName(String newName){
        name=newName;
    }

    public void setBookCode(int newCode){
        bookCode=newCode;
    }
}

class library {
    private ArrayList books=new ArrayList();

    public void getList(){
        for(int bk:books){
            String bName=books(bk).readName();
            System.out.println((bk+1)+")  "+bName);
        }
    }
}

public class libTest{
    public static void main(String[] args){
        library newLib= new library();
        System.out.println("code working");
   }
}

有任何改变,我必须在编译器设置??或者是代码。


当前回答

在我的案例中,在模块的构建中。gradle mainClassName赋值必须声明完全限定的类名,即。与主类源代码文件中指定的包名相同。

其他回答

在我的案例中,在模块的构建中。gradle mainClassName赋值必须声明完全限定的类名,即。与主类源代码文件中指定的包名相同。

什么都试过了,运气不佳。最后,对我来说(在Mac上)有效的简单解决方案是:

当项目处于打开状态时,转到查找器并将SRC目录移出项目文件夹。IntelliJ意识到src不再存在,并更新自己。 在项目仍然打开的情况下,将SRC目录移回原位。IntelliJ更新了它的项目配置,此时一切正常。

你可以在项目目录下的pom.xml文件上运行maven命令:

MVN清洁安装

在我的例子中,我配置了(相对)长的vm参数。将这些参数(只要可能)转换为环境变量为我解决了这个问题

简单的解决方案是在命令行中转到受支持的文件夹,其中是项目的根文件夹。您应该在您的机器中安装SBT。

如果你已经安装了sbt,请运行命令“sbt package”,这将重新编译项目,如果它成功,回到intelliJ它将工作。