. Advertisement .
..3..
. Advertisement .
..4..
I’m building a new program, but when I run it, an error pops up. The error displayed is as follows:
"Index was outside the bounds of the array." "Index was outside the bounds of the array."
I have tried several workarounds, but they still do not get the desired results. If you have come across this situation and have a solution for the index was outside the bounds of the array problem, pls let me know. This is what I do:
if (posStatus[intUsersInput-1] == 0) //if pos is empty
{
posStatus[intUsersInput-1] += 1;
}//set it to 1
public int[] posStatus;
public UsersInput()
{
this.posStatus = new int[8];
}
int intUsersInput = 0; //this gets try parsed + validated that it's 1-9
if (posStatus[intUsersInput-1] == 0) //if i input 9 it should go to 8?
{
posStatus[intUsersInput-1] += 1; //set it to 1
}
Thanks.
//if i input 9 it should go to 8?
Hi, your problem is pretty simple. You just continue to work with the elements of the array. While looping through the array you should count 8 elements, they are still going to be array(0) – array(7) however.
An array can be declared that contains 8 elements, not 9.
This means that postStatus will have 8 elements from index 1 to 7.