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: error with equals in arraylist loop

  1. #1
    Junior Member Randor's Avatar
    Join Date
    Nov 2012
    Location
    Olean, NY
    Posts
    11
    My Mood
    Cool
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default error with equals in arraylist loop

    Hello,


    I have an arraylist:
    public static ArrayList<String> CurrentUsers = new ArrayList<>();
    This arraylist has the names of the current users in it I have done tests and they are in by using the built in add(xx); function.

    I get input into a server through here:
                        String Grabber= INPUT.nextLine();
     
                        String[] inFeed = Grabber.split(",");

    once I have the input into the inFeed array i am trying to do a check:
                            for(int i = 0; i < GameServer.CurrentUsers.size(); i++) {
     
                                System.out.println("made it! - " + CurrentUsers.get(i) + "\n");
     
                                if(GameServer.CurrentUsers.get(i).equals(inFeed[1])) { //<---- Error here!!!!
     
                                    System.out.println(GameServer.CurrentUsers.get(i) + " " +inFeed[1] + "\n");
     
                                    GameServer.CurrentUsers.remove(i);
     
     
                                }
     
                            }

    at this line:
    if(GameServer.CurrentUsers.get(i).equals(inFeed[1])) {

    I am getting this error:
    java.util.NoSuchElementException: No line found

    any idea why??

    ps: please excuse the excessive amount of system.out.println's as I am using them for error testing..
    When I die, I want it to be peacful and in my sleep, like my grandfather. Not flailing and screaming like the people in his car!!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,552
    Thanks
    45
    Thanked 1,953 Times in 1,927 Posts

    Default Re: error with equals in arraylist loop

    java.util.NoSuchElementException: No line found
    Where is that error happening? What method is throwing it?
    Can you post the full contents of the error message?

    I don't see where the ArrayList class's get() method throws that error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Randor (November 27th, 2012)

  4. #3
    Junior Member Randor's Avatar
    Join Date
    Nov 2012
    Location
    Olean, NY
    Posts
    11
    My Mood
    Cool
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: error with equals in arraylist loop

    Found the issue, actually 2 of them...

    First off the error was actually coming because I was using a while(true) loop instead of a while(hasNextLine()) loop, and it was not doing the check because of simple human error in typing, it should have been inFeed[0] not inFeed[1].

    Sorry for the troubles..
    When I die, I want it to be peacful and in my sleep, like my grandfather. Not flailing and screaming like the people in his car!!

Similar Threads

  1. ArrayList problem, help me to find out the error!
    By jinanzhaorenbo in forum Exceptions
    Replies: 1
    Last Post: July 30th, 2012, 10:55 PM
  2. Need help with ArrayList loop
    By mattslagle44 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 7th, 2012, 12:31 PM
  3. [SOLVED] I don't know why this error using get() method from the ArrayList class
    By juanp_1982 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 11th, 2012, 02:11 PM
  4. Possible Loop Error...
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 5th, 2010, 02:17 PM
  5. Error when loop used
    By anandkokatnur in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 24th, 2010, 11:17 AM