Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ArrayOutOfBoundsException

Hey guys i'm getting an ArrayOutOfBoundsException: 0

any help would be appeciated

Code:
```package tes;

import java.lang.*;
import java.util.concurrent.*;

class TDLife {
static CyclicBarrier barrier;
public static void main(String args[]) {

final int T = Integer.parseInt(args[0]);
final int N = Integer.parseInt(args[1]);
final int G = Integer.parseInt(args[2]);
final int R1 = Integer.parseInt(args[3]);
final int R2 = Integer.parseInt(args[4]);
final int R3 = Integer.parseInt(args[5]);
final int R4 = Integer.parseInt(args[6]);
final int M = Integer.parseInt(args[7]);
String[][][] arr = new String[N][N][N];

for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
for(int k = 0; k < N; k++)
arr[i][j][k] = ".";

if(N == 1)
arr[0][0][0] = "O";

else if(N == 2) {
arr[0][0][0] = "O";
arr[0][0][1] = "O";
arr[0][1][0] = "O";
}

else {
arr[0][0][0] = "O";
arr[0][0][1] = "O";
arr[0][0][2] = "O";
}

private String currentCells[][][];
private String copies[][][];
private int J;

public NewThread(String cells[][][], int t) {
J = t;
currentCells = cells;
copies = new String[N][N][N];

for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
for(int k = 0; k < N; k++)
copies[i][j][k] = ".";
}

public void copyArray(String cells[][][]) {
currentCells = cells;
}

public void run() {
int S = N*N*N;

for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
for(int k = 0; k < N; k++) {

int C = (i*(N*N)) + (j*N) + k;

if(((M == 0) &&(((J*S)/T <= C) && (C < ((J+1)*S)/T)))
|| ((M == 1) && (C%T == J))) {

int on = 0;

for (int i1 = -1; i1 < 2; i1++) {
for (int j1 = -1; j1 < 2; j1++) {
for (int k1 = -1; k1 < 2; k1++) {
int ic = i+i1;
int jc = j+j1;
int kc = k+k1;

if(ic < 0)
ic = N - 1;
if(jc < 0)
jc = N - 1;
if(kc < 0)
kc = N - 1;
if(ic == N)
ic = 0;
if(jc == N)
jc = 0;
if(kc == N)
kc = 0;

if(currentCells[ic][jc][kc] == "O")
on++;
}
}
}

if((currentCells[i][j][k] == ".") && ((on >= R1) && (on <= R2)))
currentCells[i][j][k] = "O";
else if ((currentCells[i][j][k] == "O") && ((on >= R4) && (on <= R3)))
currentCells[i][j][k] = ".";
}
}
}
}

try {
barrier.await();
}
catch (InterruptedException ex) {
return;
}
catch (BrokenBarrierException ex) {
return;
}
}

public void copyOver() {

for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
for(int k = 0; k < N; k++)
currentCells[i][j][k] = copies[i][j][k];
}
}

for(int i = 0; i < T; i++)

barrier = new CyclicBarrier(T, new Runnable () {
public void run() {
for(int i = 0; i < T; i++)
}
}
);

for(int i = 0; i < G; i++) {
for(int j = 0; j < T; j++)

barrier.reset();
}
}
}```
PHP Code:
``` *.  ```

• My eyes hurt.

You never heard of indenting code?

But anyway, WHERE do you get the error????

• Refer to the statement mentioned below in the method run():

if(((M == 0) &&(((J*S)/T <= C) && (C < ((J+1)*S)/T)))
|| ((M == 1) && (C%T == J))) {

(J*S)/T may not always be an integer . I think you should try rounding the result of the division before using it.

•