Results 1 to 16 of 16
  1. #1
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Data management (facebook style)

    Sorry, editted this a few times and found my problem:

    It seems like I don't know much about iterators. Help appreciated!
    Java Code:
    public Iterator<String> getFriends() {
    		if (friendList.iterator().hasNext())
    			return friendList.iterator();
    		return null;
    	}
    
    	public String toString() {
    		Iterator<String> it = getFriends();
    		
    		String allData = name + " (" + userStatus + ") : ";
    		if (it.hasNext())
    			allData += it.next();
    		while (it.hasNext()) {
    			allData += ", " + it.next();
    		}
    		
    		return allData;
    	}
    
    
    private ArrayList<String> friendList;
    Last edited by Jossos; 01-07-2012 at 01:39 PM.

  2. #2
    jihad is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default Re: Data management (facebook style)

    how did you create database object

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default Re: Data management (facebook style)

    @Jossos: please don't remove your original question; this entire thread is useless now ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Updated main post, sorry for the confusion.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default Re: Data management (facebook style)

    Quote Originally Posted by Jossos View Post
    Updated main post, sorry for the confusion.
    Thanks for your cooperation; now the google links aren't completely worthless anymore ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Quote Originally Posted by JosAH View Post
    Thanks for your cooperation; now the google links aren't completely worthless anymore ;-)

    kind regards,

    Jos
    actually do need help though. Iterations arent something I really comprehend.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Data management (facebook style)

    Quote Originally Posted by Jossos View Post
    actually do need help though. Iterations arent something I really comprehend.
    Please tell the details of your question. All I see is "need help" which is not an answerable question.

  8. #8
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Quote Originally Posted by Fubarable View Post
    Please tell the details of your question. All I see is "need help" which is not an answerable question.
    I put the code I need help with in the first post, but I guess I'll post it again.

    this code crashed my program, and I can't figure out why.

    Java Code:
    public Iterator<String> getFriends() {
            if (friendList.iterator().hasNext())
                return friendList.iterator();
            return null;
        }
     
        public String toString() {
            Iterator<String> it = getFriends();
             
            String allData = name + " (" + userStatus + ") : ";
            if (it.hasNext())
                allData += it.next();
            while (it.hasNext()) {
                allData += ", " + it.next();
            }
             
            return allData;
        }
    
    private ArrayList<String> friendList;

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Data management (facebook style)

    Quote Originally Posted by Fubarable View Post
    Please tell the details of your question...
    This includes any and all error messages, and anything else you can tell us. And how are you using this code? Please read the link in my signature links below on "smart questions" which will tell you this and other question details that will make your question an answerable one.

  10. #10
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Quote Originally Posted by Fubarable View Post
    This includes any and all error messages, and anything else you can tell us. And how are you using this code? Please read the link in my signature links below on "smart questions" which will tell you this and other question details that will make your question an answerable one.
    I was assuming I am using iterators the wrong way, or appending to the String in the wrong way. I don't know how to see error messages in eclipse. I just get a message saying "do you want to open the debug perspective now?" which just tells me the location of my project. Nothing useful there.

    If I have to show the code that uses this method, and the classes used in that method, and the classes used in the methods in those classes, It's gonna be a lot of code to post.

    Atleast let me know if I'm using iterators correctly or not if you can.

    This code is of particular concern:

    Java Code:
    Iterator<String> it = getFriends();
    Is this even logical? does it just place the whole friends list into the iterator as Im assuming it does? regardless, when I test my code, initially the getFriends() returns nothing since the list is empty.

    I can't think of anything else I can tell you. Unless you wanna guide me as to how to see error messages in eclipse. It gives me the same unhelpful error messages every time (regardless of project or code).
    Last edited by Jossos; 01-07-2012 at 10:05 PM.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Data management (facebook style)

    No, that's not logical since an ArrayList<String> will never equal an Iterator. This wouldn't crash the program but would prevent it from compiling, and if so, you should see a compilation error. Again -- do you see any? You can get the ArrayList's iterator though and use that if you desire.

    Edit, now I'm confused. You state that getFriends() "is an arrayList<String>", but it's not. I'll wait for further clarification.
    Last edited by Fubarable; 01-07-2012 at 10:02 PM.

  12. #12
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Quote Originally Posted by Fubarable View Post
    No, that's not logical since an ArrayList<String> will never equal an Iterator. This wouldn't crash the program but would prevent it from compiling, and if so, you should see a compilation error. Again -- do you see any? You can get the ArrayList's iterator though and use that if you desire.

    Edit, now I'm confused. You state that getFriends() "is an arrayList<String>", but it's not. I'll wait for further clarification.
    My mistake, friendsList is an arrayList<String>, not the method getFriends().

    How would I go about using an iterator to grab everything from an arrayList and put it into the iterator?

  13. #13
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    should note, in eclipse IDE, i have NEVER got a compilation error. Either I have been doing a good job, or that's not how this IDE rolls. (Or im looking in the wrong places)

    Here, I don't know what this means:

    Data management (facebook style)-debugg.png
    Last edited by Jossos; 01-07-2012 at 10:26 PM.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Data management (facebook style)

    You're code is generating a NullPointerException. I'm guessing that this is also not being displayed in Eclipse's Console window? You're not swallowing exceptions anywhere in your code are you?

  15. #15
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Quote Originally Posted by Fubarable View Post
    You're code is generating a NullPointerException. I'm guessing that this is also not being displayed in Eclipse's Console window? You're not swallowing exceptions anywhere in your code are you?
    If you mean catching exceptions, no. I don't know what swallowing exceptions means. Man This business is frustrating. I can tell it's crashing because the iterator is messed up.

  16. #16
    Jossos is offline Member
    Join Date
    Nov 2011
    Posts
    21
    Rep Power
    0

    Default Re: Data management (facebook style)

    Ok I've just restarted the project. If I get the same problems again, I will post.

Similar Threads

  1. Hi!! Please like my status on facebook... NOT!!!
    By Majikk in forum Introductions
    Replies: 1
    Last Post: 12-04-2011, 02:04 PM
  2. Replies: 1
    Last Post: 06-01-2011, 03:46 AM
  3. Facebook
    By sunde887 in forum Suggestions & Feedback
    Replies: 0
    Last Post: 04-30-2011, 10:27 AM
  4. facebook-like framework
    By robertgrzeda in forum Web Frameworks
    Replies: 0
    Last Post: 04-16-2010, 12:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •