1 Error on line 12(CodeAcademy Learn Java, personal library)


import java.util.HashMap;
public class Library {
 public Library () {
  public void getFinishedBooks(HashMap<String,Boolean> library) {
    if (library.size() < 1) {
    else {
      for (Boolean book : library.keySet()) {
        if (book == true) {
  public static void main(String [] args) {
    HashMap<String,Boolean> myBooks = new HashMap<String,Boolean>();
    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();

Library.java:11: error: incompatible types: String cannot be converted to Boolean
for (Boolean book : library.keySet()) {
1 error

I dont understand, how i can fix error. Can anyone help?


for (Boolean book : library.keySet())

book is not of type boolean, book will contain the hashmap keys (so titles of books), not the values belonging to keys, which are booleans.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.