我是 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 许可协议
这可能会有所帮助:
Rebuild Project
”。有时 Intellij 不会重写类,因为它们已经存在,这样您就可以要求 Intellij 重写所有内容。2)“运行”菜单->“
Edit configuration
”->删除配置文件->添加回配置文件(如果是Java应用程序,则为“应用程序”),从“主类”下拉列表中选择您的主类菜单。3)“构建”菜单->“
Rebuild Project
”。