错误:无法在 intelliJ IDE 中找到或加载主类

新手上路,请多包涵

我是 Java 的初学者,我正在尝试使用 IntelliJ 运行我的代码,该 IntelliJ 我刚刚安装为带有 JDK 1.7 的 IDE。以下代码甚至无法编译并不断给我错误:

 Error: Could not find or load main class libTest

代码

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");
   }
}

我必须在编译器设置中进行任何更改吗?或者是代码。

原文由 Confused Mailman 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 397
1 个回答

这可能会有所帮助:

  1. “构建”菜单 -> “ Rebuild Project ”。有时 Intellij 不会重写类,因为它们已经存在,这样您就可以要求 Intellij 重写所有内容。

2)“运行”菜单->“ Edit configuration ”->删除配置文件->添加回配置文件(如果是Java应用程序,则为“应用程序”),从“主类”下拉列表中选择您的主类菜单。

3)“构建”菜单->“ Rebuild Project ”。

原文由 Ehsan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题