0
我嘗試使用if語句來查看索引是否返回null,如果它跳過則跳過,但它仍然繼續獲取數組索引超出邊界異常。對象的Java二維數組 - 如何檢查某個索引是否存在?
...
if(tiles[x+a][y+b] == null){
System.out.println("Would have been an error");
} else if(tiles[x+a][y+b].getType() == type) {
tiles[x+a][y+b].setTile(type);
} else {
System.out.println("Not found");
}
...
主要是前兩行是問題所在。我試圖讓它通過數組,但會跳過任何會使數組索引超出界限例外的東西。如果您需要更多背景信息,請告訴我。我試圖儘可能地減少它。