Not sure where I went wrong: "Cannot find symbol" and "missing Method body"


#1



Hey there folks,

I'm struggling to sort out what the error message "Cannot find symbol" might mean as it relates to what I've written for this project. Additionally, I'm getting the error that states, "missing method body, or declare abstract" for my first 'get' statement.

Can anyone with keen eyes scan through my work so far and see where I've flubbed up?

Thank you!


https://www.codecademy.com/en/courses/learn-java/projects/personal-library?link_content_target=interstitial_project

Library.java:7: error: missing method body, or declare abstract
public void getFinishedBooks(HashMap Library); {
^
Library.java:8: error: cannot find symbol
if (Library.size() < 1) {
^
symbol: method size()
location: class Library
Library.java:11: error: cannot find symbol
for (String book: Library.KeySet()) {
^
symbol: method KeySet()
location: class Library
Library.java:13: error: cannot find symbol
if (Library.get(book) == true ) {
^
symbol: method get(String)
location: class Library
Library.java:23: error: cannot find symbol
myBooks.add("Pandora's Star", true);
^
symbol: method add(String,boolean)
location: variable myBooks of type HashMap
Library.java:24: error: cannot find symbol
myBooks.add("Return of the King", false);
^
symbol: method add(String,boolean)
location: variable myBooks of type HashMap
Library.java:25: error: cannot find symbol
myBooks.add("Initiate Brother", true);
^
symbol: method add(String,boolean)
location: variable myBooks of type HashMap
Library.java:26: error: cannot find symbol
myBooks.add("A Way of Kings", false);
^
symbol: method add(String,boolean)
location: variable myBooks of type HashMap
8 errors


import java.util.HashMap;

public class Library{
 
  public Library(){}
  
    public void getFinishedBooks(HashMap<String, Boolean> Library); {
    if (Library.size() < 1) {
      System.out.println("Time to read!");
    } else {
      for (String book: Library.KeySet()) {
        
        if (Library.get(book) == true ) {
          System.out.println("This book is complete!" + book);
        }
      }
     }
    
  }
     public static void main(String[] args) {
       
       HashMap<String, Boolean> myBooks = new HashMap<String, Boolean>();
       myBooks.add("Pandora's Star", true);
       myBooks.add("Return of the King", false);
       myBooks.add("Initiate Brother", true);
       myBooks.add("A Way of Kings", false);
       Library myLibrary = new Library();
       myLibrary.getFinishedBooks(myBooks);
     }
  
}


#2

That semi-colon doesn't look right.


#3

Thanks mtf! That solves the "get" error! You've got sharp eyes!

As for the 'symbol' error, I'm still a bit stumped. I'll keep scanning in my method.

Thanks for your help!


#4

Yeah, I don't know how much more help I can be, save a pair of eyes. Stuck myself on step 5.

import java.util.HashMap;

public class Library {
  public Library() {
    
  }
  pulbic void getFinishedBooks(HashMap<String, Boolean> library) {
    
  }
  public static void main(String[] args) {
    
  }
}

Errors

Library.java:7: error: <identifier> expected
  pulbic void getFinishedBooks(HashMap<String, Boolean> library) {
        ^
Library.java:7: error: invalid method declaration; return type required
  pulbic void getFinishedBooks(HashMap<String, Boolean> library) {
              ^
2 errors

As we can see, Java is not my language.


#5

Oops, I think I spotted it -

I think you meant to type 'public', rather than 'pulbic' in your getFinishedBooks line. Hopefully that clears it up!


#6

D'oh! Who's got good eyes, now? Thanks!

Now I'm getting this far, and raising the same error as you...

import java.util.HashMap;

public class Library {
  public Library() {
    
  }
  public void getFinishedBooks(HashMap<String, Boolean> library) {
    if (library.size() < 1) {
      System.out.println("library is empty");
    } else {
      for (String book : library.KeySet()) {
        
      }
    }
  }
  public static void main(String[] args) {
    
  }
}

Error

Library.java:11: error: cannot find symbol
      for (String book : library.KeySet()) {
                                ^
  symbol:   method KeySet()
  location: variable library of type HashMap<String,Boolean>
1 error

#7

Hoho! I solved it! Maybe we have the same issue? I accidentally used

   myBooks.add("Pandora's Star", true);

But a HashMap prefers if you write it like:

   myBooks.put("Pandora's Star", true);

Happy coding!


#8

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