Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Im trying to print all the Books in Book Class with the Iterator and while statement

  1. #1
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Im trying to print all the Books in Book Class with the Iterator and while statement

    Trying to find why this code wont compile. it returns error code "cannot find symbol- variable book"

     public void ListBooksIterator()
        {
            Iterator<String> it = book.iterator();
            while(it.hasNext()) 
            {
                System.out.println(it.next());
            }
        }

    Trying to print all the Books in the book Class.cheers


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Im trying to print all the Books in Book Class with the Iterator and while statement

    We can't really do much with this code. Instead, post an SSCCE that demonstrates the problem. Where is the book variable declared and initialized?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Im trying to print all the Books in Book Class with the Iterator and while statement

    "cannot find symbol- variable book"
    The error message means the compiler can not see the declaration of the symbol, which the compiler believes to be a variable name based on it's use. Where did you declare book and why is this method not within scope?
    Without the rest of the class code not much more advice to offer.

Similar Threads

  1. CLASS BOOK HELP. Please. Please.
    By ITshard in forum Object Oriented Programming
    Replies: 3
    Last Post: August 27th, 2012, 11:04 AM
  2. Calling a print method from another class (printing array)
    By Kaldanis in forum Object Oriented Programming
    Replies: 7
    Last Post: November 25th, 2011, 12:32 PM
  3. Class that will simulate a book catalog system
    By fatika26 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 17th, 2011, 07:34 AM
  4. Replies: 6
    Last Post: July 21st, 2011, 07:45 AM
  5. [SOLVED] Iterator next import class?
    By daydreamer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2010, 04:51 AM