ArrayOutOfBoundsIndexException
in
Core Library Questions
•
1 year ago
Hi,
I am creating an RTS game involving a server and a client. I have recently been getting an ArrayOutOfBoundsIndexException error that I cant seem to solve. Any help would be appreciated.
this is the server
- import processing.net.*; //Imports processing.net.* Library -- for server
- Server gameServer; //Server -- This program is the server
- Client gameClient; //Client -- The partner program is the Client
- String input; //Stores data recieved from Client
- int data[]; //Separates data stored in input
- void ServerSetup(){
- if(NumberOfUnits > 0){ //If you have any units
- //Send the array indexes and Team Coordinates to the client
- gameServer.write(0 + " " + xCoordinate + " " + yCoordinate + "\n");
- }
- //Receive data from client
- gameClient = gameServer.available();
- //If the Client is sending information
- if (gameClient != null){
- //Put the input into a string
- input = gameClient.readString();
- //Separate the elements of the string
- if(input.indexOf("\n") != -1){
- input = input.substring(0, input.indexOf("\n")); // Only up to the newline
- }
- //Split values into an array
- data = int(split(input, ' '));
- //Use the values to generate the positions and images of the opposing team
- println(data[0]); //The ArrayOutOfBoundsIndexException occurs between 0 and 5 minutes randomly on any of these println lines
- println(data[1]);
- println(data[2]);
- }
- }
this is the client
- import processing.net.*; //Imports processing.net.* Library -- for server
- Client gameClient; //Client -- The partner program is the Client
- String input; //Stores data recieved from Client
- int data[]; //Separates data stored in input
- void ClientSetup() {
- if(NumberOfUnits > 0){
- //Send the array indexes and Team Coordinates to the client
- gameClient.write(0 + " " + xCoordinate + " " + yCoordinate + "\n");
- }
- //If the Server is sending information
- if (gameClient.available() > 0) {
- //Put the input into a string
- input = gameClient.readString();
- //Separate the elements of the string
- if(input.indexOf("\n") != -1){
- input = input.substring(0, input.indexOf("\n"));
- }
- //Split values into an array
- data = int(split(input, ' '));
- //Use the values to generate the positions and images of the opposing team
- println(data[0]);
- println(data[1]);
- println(data[2]);
- }
- }
1