Results 1 to 4 of 4
  1. #1
    anoorally is offline Member
    Join Date
    Jan 2012
    Posts
    28
    Rep Power
    0

    Default String to ArrayList error

    Hi,
    I have a Game class which connects to a server. I made 4 instances of them. Each one connecting to teh server is given a turn number.
    As soon as all of them get connected to the server, they are all forwarded an array of String of length 5 containing default player names from which they wud retrieve their default names given depending on the turn number they were given and set it in an ArrayList they have locally to store the players name.
    The String array sent has the first index "Name Set" to identify the rest of the array as containing the player names.

    The problem here is that all the first 3 instances connect without any fault. But the 4th instance encounters an error as follows:

    Error in reading thread: Index: 0, Size: 0
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at dominogameClient.GameGUI.filterData(GameGUI.java:6 23)
    at dominogameClient.GameGUI$constantReading.run(GameG UI.java:1161)
    at java.lang.Thread.run(Thread.java:722)

    the code it points to at line 623 is:
    Java Code:
    txtInfo.setText(playerNames.get(currentTurn) + "'s turn");
    Any one knows whats wrong please? Thank you in advance.

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

    Default Re: String to ArrayList error

    You've got an error in code not shown. It looks like the array has size 0 at that time. You'll need to look back in your code to see why.

  3. #3
    anoorally is offline Member
    Join Date
    Jan 2012
    Posts
    28
    Rep Power
    0

    Default Re: String to ArrayList error

    But then how come the 3 first instances work without throwing any error?
    The code just above that line prints the content of the array:
    Java Code:
                    //------
                    for(String nm:playerNames){
                       print("->"+ nm);
                    }
                    //------
                    txtInfo.setText(playerNames.get(currentTurn) + "'s turn");
    the output of the 3 other instances are:
    ->Player 1
    ->Player 2
    ->Player 3
    ->Player 4

    its
    Last edited by anoorally; 03-04-2012 at 07:46 PM.

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

    Default Re: String to ArrayList error

    Quote Originally Posted by anoorally View Post
    But then how come the 3 first instances work without throwing any error?
    That's a very good question, and if I knew your code or if my crystal ball weren't in the shop, I'd be able to tell you why, but since I can't use either, all I can do is commiserate and again say that you've got a bug, pure and simple, and it's somewhere in code not shown.

    Seriously though, there's not a chance in Hades that we can help without more information.

Similar Threads

  1. How to read a string in a ArrayList?
    By warchieflll in forum New To Java
    Replies: 6
    Last Post: 12-09-2010, 06:58 PM
  2. Replies: 12
    Last Post: 11-26-2010, 09:33 AM
  3. Replies: 1
    Last Post: 11-04-2010, 07:53 PM
  4. ArrayList out of bound, split string error.
    By Kerrai in forum New To Java
    Replies: 4
    Last Post: 11-03-2010, 10:37 AM
  5. Putting a string into ArrayList<String>
    By k4ff1n34dd1c7 in forum New To Java
    Replies: 5
    Last Post: 03-23-2009, 06:10 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
  •