java - 错误 : Could not find or load main class in intelliJ IDE

标签 java compiler-errors intellij-idea

我是 Java 初学者,我正在尝试使用 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");
   }
}

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

最佳答案

这可能会有所帮助:

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

2) “运行”菜单 -> “编辑配置” -> 删除配置文件 -> 添加回配置文件(“应用程序”,如果它是 Java 应用程序),从“主类”下拉菜单。

3)“构建”菜单 -> “重建项目”。

关于java - 错误 : Could not find or load main class in intelliJ IDE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10654120/

相关文章:

java - 与玩家一起移动绳索 Swing

oracle - Oracle函数错误: ORA-00932: inconsistent datatypes: expected CHAR got MDSYS.SDO.GEOMETRY

gradle - IDEA报告build.gradle.kts中ShadowJar任务的错误,而./gradlew运行正常

java - 如何在 Java 类中实现 Kotlin 挂起方法?

java - 错误:任务 ':app:dexDebug'的执行失败。 > com.android.ide.common.process.ProcessException:

JavaFX 如何最小化 ImageView 点击窗口?

java - 如何根据特定顺序对 hibernate 结果进行排序

c++ - 使用 std::tuple 作为 std::unordered_map 的键

java - 将图像拖放到Jpanel中并将其放入应用程序目录中

Android Studio 的窗口未呈现/空白