Error: Could not find or load main class in intelliJ 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.

47 Answers
47

This might help:

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) “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)”Build” menu -> “Rebuild Project“.

Leave a Comment