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 8 of 8

Thread: System.out.println Error when using Iterator

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default System.out.println Error when using Iterator

    Hi Guys

    Im new to programming and Java, but im willing to learn and trying hard using a book `Objects first with Java`.
    Im trying to create a program for a Library where Members can join and loan books. But i keep getting an Error when using the Iterator.
    My code is below:

    import java.util.ArrayList;
    import java.util.Iterator;
    /**
     * Write a description of class Library here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Library
    {
        private ArrayList<Book> books;
        private ArrayList<Member> members;
        private int nextMemberNumber;
     
        /**
         * Constructor for objects of class Library
         */
        public Library()
        {
            books = new ArrayList<Book>();
            members = new ArrayList<Member>();
            nextMemberNumber = 1;
        } 
        public void AddNewMember( Member newMember )
        {
          members.add(newMember);
          nextMemberNumber++;
        }
        public int NumberOfMembers()
        {
            return members.size();
        }
        public void ShowMembers( String getDetails )
        {
            Iterator<Member> it = members.iterator();
            while(it.hasNext())
            {
                Member t = it.next();
                System.out.println(t.getMember());// --------------------This is where the error is when i complie. getMmember?
            }
        }
        public int numberOfMembers()
        {
            return members.size();
        }
        }

    Any help would be great, i can see people really know what there talking about on here thats why i joined. Thanks Guys

    Willo
    Last edited by jps; December 3rd, 2012 at 05:25 PM. Reason: Added code tags


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: System.out.println Error when using Iterator

    Can you show us the error message?

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: System.out.println Error when using Iterator

    Hi Willo can you show the error message ?

  4. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: System.out.println Error when using Iterator

    Oh, rubbish! This is a zombie.

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: System.out.println Error when using Iterator

    Not sure what your error is, you could try this :

    public void ShowMembers( String getDetails )
    {
    for(int i = 0 ; i < members.size() ; i++) {
    Member member = (Member) members.get(i);
    if(member.getMember() != null ) {
    System.out.println(member.getMember());
    }
    }
    }

    I have not been able to test this as i do not have the Member class but you might as well try it

    Also you have a parameter, "getDetails" which is currently un-used

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: System.out.println Error when using Iterator

    Quote Originally Posted by Luka View Post
    Not sure what your error is, you could try this :

    ...
    I have not been able to test this as i do not have the Member class but you might as well try it

    Also you have a parameter, "getDetails" which is currently un-used
    Welcome to the forums Luka. Please note the date on this thread as it is half a year old. Also, please read the forum announcement and the following:
    http://www.javaprogrammingforums.com...n-feeding.html

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: System.out.println Error when using Iterator

    @conniesookie, welcome to the forums. Please read the posts above, in particular post #4 (this thread is half a year old) and 6 (please do not spoonfeed).

  8. #8
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: System.out.println Error when using Iterator

    I have gone through your code, There is no question of getting the error.

Similar Threads

  1. System.out.println Not Working
    By manjula in forum JavaServer Pages: JSP & JSTL
    Replies: 6
    Last Post: November 27th, 2012, 07:25 AM
  2. use of System.out.println(""); error....
    By rohan22 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 16th, 2011, 10:49 AM
  3. How to modify System.out.println()
    By emailkia in forum Java Theory & Questions
    Replies: 6
    Last Post: April 25th, 2011, 12:40 AM
  4. what is System,out,println in System.out.println()?
    By koteshk in forum Java Theory & Questions
    Replies: 2
    Last Post: April 18th, 2011, 12:28 AM
  5. How can i print rows 1 by 1 using System.out.println?
    By noFear in forum Java Theory & Questions
    Replies: 2
    Last Post: August 26th, 2010, 07:35 AM

Tags for this Thread