错误:无法在intelliJ IDE中找到或加载主类 [英] Error: Could not find or load main class in intelliJ IDE

查看:1683
本文介绍了错误:无法在intelliJ IDE中找到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的初学者,我正在尝试使用IntelliJ运行我的代码,我刚刚安装了JDJ 1.7作为我的IDE。以下代码保持甚至不编译并一直给我错误:

I'm a beginner in Java and am trying to run my code using IntelliJ that I just installed as my IDE with JDK 1.7. The following piece of code keeps does not even compile and keeps giving me the error:

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

我必须在编译器设置??或者是代码。

Is there any change that i have to make in the compiler settings?? Or is it the code.

推荐答案

这可能有所帮助:

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

1) "Build" menu -> "Rebuild Project". Sometimes Intellij doesn't rewrite the classes because they already exist, this way you ask Intellij to rewrite everything.

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

2) "Run" menu -> "Edit configuration" -> delete the profile -> add back the profile ("Application" if it's a Java application), choose your main class from the "Main Class" dropdown menu.

3)构建菜单 - >重建项目

3)"Build" menu -> "Rebuild Project".

这篇关于错误:无法在intelliJ IDE中找到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆