无法从文本中读取我的"map"布局并将其放入数组中。应用程序只是崩溃



嗨,我正在尝试制作我的第一个Android游戏,但我在制作Tilemap时遇到了问题。我在阅读前两行时没有问题,但它不会加载网格。(我已经正常制作了游戏,我试图将其传输到应用程序,所以我知道代码有效,但似乎无法使其在 Android Studio 上运行(。该应用程序由于某种原因崩溃 这是代码

e public void createTilemap(Context context) {
BufferedReader reader;
try {
final InputStream file = context.getAssets().open("map1.txt");
reader = new BufferedReader(new InputStreamReader(file));
String line = reader.readLine();
gridWidth = Integer.parseInt(line);
line = reader.readLine();
gridHeight = Integer.parseInt(line);
tileMap = new int[gridHeight][gridWidth];
String delimiters = " ";
for(int row = 0; row < gridHeight; row++){
line = reader.readLine();
String[] tempStorage = line.split(delimiters);
for(int col = 0; col < gridWidth; col++){
line = tempStorage[col];
int temp = 0;
temp = Integer.parseInt(line);
tileMap[row][col] = temp;
}
Log.d("this is my deep array", "deep arr: " + Arrays.deepToString(tileMap));
}

}catch (IOException e){
e.printStackTrace();
}

这是我尝试从中读取的文件

提前谢谢。

修复了IT。数组大小错误,我要求 32 并且数组是 31 :D

最新更新