Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8040403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:53:02+00:00 2026-06-05T03:53:02+00:00

I’m creating a game in java and I’m attempting to create a multiplayer for

  • 0

I’m creating a game in java and I’m attempting to create a multiplayer for it, when the game first starts, the level is loaded and the client is added to a playerlist which is clientside, the client will iterate through the list and add more if the server tells it to but the problem is that I’m getting ‘ArrayIndexOutOfBoundsException’ whent he game first starts, I’ve instructed my game to ignore it, I cant seem to fine the problem.

I’m assuming its something to do with creating new player and the time it takes for the threads to do their work but was hoping someone could help!

The message var is a String recieved fromt he server formatted like this:

name;address;posX;posY;fakeRotation;rotation;rotationSpeed;speed;sheildEnabled;sheildHealth;health

Here is an example of what the server sends:

Luke;/127.0.0.1:53701;50.0;50.0;0.0;0.0;0.0;0.0;true;100;100

Here are the vars:

String[] decrypted = message.split(",");
String[] commands = decrypted[x].split(";");

Here’s the piece of code that’s troubling me:

 boolean newPlayer = true;
        if(Main.level.playerList != null)
        {
            try
            {
                for(int p = 0; p < Main.level.playerList.size(); p++)
                {
                    if(Main.level.playerList.get(p).address.toString().equals(commands[1]))
                    {
                        newPlayer = false;
                        break;
                    }
                }

                if(newPlayer)
                {
                    Player player = new Player(50, 50, 100, 150, commands[1], Main.level.shipImage1, Main.level.thrusterFlamesSprite1, Main.level.shieldSprite1);
                    Main.level.playerList.add(player);
                }

                for(int p = 0; p < Main.level.playerList.size(); p++)
                {
                    Player player = Main.level.playerList.get(p);

                    if(player.address.equals(commands[1]))
                    {
                        // name:address:posX:posY:fakeRotation:rotation:rotationSpeed:speed:sheildEnabled:sheildHealth:health
                        player.name = commands[0];
                        player.address = commands[1];
                        player.pos[0] = Double.parseDouble(commands[2]);
                        player.pos[1] = Double.parseDouble(commands[3]);
                        player.fakeRotation = Float.parseFloat(commands[4]);
                        player.rotation = Float.parseFloat(commands[5]);
                        player.rotationSpeed = Double.parseDouble(commands[6]);
                        player.speed = Double.parseDouble(commands[7]);
                        player.sheildEnabled = Boolean.parseBoolean(commands[8]);
                        player.sheildStrength = Integer.parseInt(commands[9]);
                        //player.health = Integer.parseInt(commands[10]);
                    }
                }
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                System.out.println("Array index out of bounds, continuing.");

                e.printStackTrace();
            }
        }

Hopefully someone can help, like I said i think its somethign to do with adding a ‘new’ item but I can’t find any way to make it work!

The stack trace I receive is:

java.lang.ArrayIndexOutOfBoundsException: 1
at multiplayer.Translator.interperate(Translator.java:28)
at multiplayer.GameClient.run(GameClient.java:81)

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:53:04+00:00Added an answer on June 5, 2026 at 3:53 am

    According to the stack trace, is the error happening on the health line? If so, decrypted[x] may not have enough semicolons in it.

    edit –

      String[] commands = decrypted[x].split(";");
    

    So, what is x?
    When you look at all decrypted[x] do you see what you expect? Is that value the ‘Luke’ data you posted earlier?

    edit – also, I recommend you replace the 0 and 1 in pos[0] and pos[1] with static final constants:

      private static final int X_COORD = 0;
      private static final int Y_COORD = 1;
      /* ... snip ... */
      player.pos[X_COORD] = Double.parseDouble(commands[2]);
      player.pos[Y_COORD] = Double.parseDouble(commands[3]);
    

    The point of this is to allow your code to refer to the X and Y coordinates by a descriptive constant instead of a number. While right now you know what 0 and 1 mean, a few months from now you won’t, and when you look back ont he code you’ll be mystified or confused. Adding the constants means you don’t have to remember. It will also help you spot errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.