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.
libTest.java
? – Lauroimport java.lang...
This happens automatically for classes in thelang
package. – Mylesmylittalibrary
class. Neither of them is the 'not found' error you quoted. Is that the actual copy/pasted code being used? Are the classes in separate files? Are they in separate packages (directories on the file-system). My comment about 'automatic' was meant to indicate 'remove thelang
imports'. ;) – MylesmylittaI:\libTest.java:40: incompatible types found : java.lang.Object required: int for(int bk:books){ ^ I:\libTest.java:41: cannot find symbol symbol : method books(int) location: class library String bName=books(bk).readName(); ^ 2 errors
– Mylesmylitta