An array index out of bounds exception, I know what that means but.. why!?

So my code here checks the “neighbourhood” of a cell, my cells are simply an array of Booleans [34 * 24] a total of 816.
When I run this code:

public void function(int x, int y){
		int n = 0;
		int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
		if(x == 0){
			x1 = x;
			x2 = x + 1;
		}
		if(x == pWidth){
			x1 = x - 1;
			x2 = x;
		}
		if(y == 0){
			y1 = y;
			y2 = y + 1;
		}
		if(y == pHeight){
			y1 = y - 1;
			y2 = y;
		}
		if(x != 0 && x != pWidth && y != 0 && y != pHeight){
			x1 = x - 1;
			x2 = x + 1;
			y1 = y - 1;
			y2 = y + 1;
		}
			
		for(int i = y1; i <= y2; i++){
			for(int j = x1; j <= x2; j++){
				if(pCell[j + i * pWidth] == true && j != x && i != y) n++;
			}
		}
}

I get an array index out of bounds… on line 29 (where it looks at the array given its position) and the value after says: 816, the length of the array.

All of those if statements at the top are to make sure I don’t get an array exception (for instance, by it checking the squares above and around 0,0) . pWidth and pHeight are the width and height of pCell (the array of Booleans 816 entries long). What do you see wrong? anything?