Error in project "Personal Library"


#1

I'm getting an error and I just can't figure it out.

Error:

Library.java:28: error: constructor Library in class Library cannot be applied to given types;
Library myLibrary = new Library(myBooks);
^
required: no arguments
found: HashMap
reason: actual and formal argument lists differ in length
Note: Library.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Code:

import java.util.HashMap;

public class Library {
public Library() {
}

public void getFinishedBooks() {
HashMap Library = new HashMap();
if (Library.size() < 1) {
System.out.println("HashMap is empty.");
}
else {
for(String book : Library.keySet()) {
if (Library.containsKey(true)) {
System.out.println(Library.get(book));
}
}
}
}
public static void main(String[] args) {
HashMap myBooks = new HashMap();

myBooks.put("Road Down The Funnel", true);
myBooks.put("Rat: A Biology", false);
myBooks.put("TimeIn", true);
myBooks.put("3D Food Printing", false);

Library myLibrary = new Library(myBooks);
myLibrary.getFinishedBooks();

}
}

Please help :slightly_smiling:


#2

If you want your library constructor to accept an argument, then you'll have to add a matching parameter.
If not, don't give it any arguments.

See how this corresponds to the error message that you are getting?


#3

I still can't spot the problem... (Sorry I'm sooo very bad)


#4

I'd like to think that I explained what the problem is, including how to fix it.