これは、ファイルから保存されたゲームデータを読み込むために使用しているメソッドです。私は何らかの点でerror15という何かを得ています。 Google上で起きた唯一の事はhttpと関係していましたが、私はそういうことはしていないので、それはできません。オブジェクトがコンソールに文字列を印刷するとき、オブジェクトは保存されたデータの最初の行を完成させますが、他の行を読み取ることはありません。私はin.nextLine();
の私の使用と関係があるかもしれない愚直さを持っています(私は代わりに何かを使うべきでしょうか?)誰かが私が間違っていることを教えてもらえれば、私はあなたを永遠に愛します。あなたが存在しない、あなたのループにdata[i][15]
にアクセスしようとするので私のロードデータメソッドで何が問題になっていますか?
/**
* Returns a 2-dimensional 15*15 array of saved world data from a file named by x and y coordinates
*/
public String[][] readChunkTerrain(int x, int y)
{
String[][] data = new String[15][15]; //the array we will use to store the variables
try {
//initiate the scanner that will give us information about the file
File chunk = new File("World/" + x + "." + y + ".txt");
Scanner in = new Scanner(
new BufferedReader(
new FileReader(chunk)));
//go through the text file and save the strings for later
for (int i=0; i<15; i++){
for (int j=0; j<=15; j++){
String next = in.next();
data[i][j] = next;
System.out.println(i + j + next); //temporary so I can see the output in console
System.out.println();
}
in.nextLine();
}
in.close(); //close the scanner
}
//standard exception junk
catch (Exception e)
{System.err.println("Error" + e.getMessage());}
return data; //send the array back to whoever requested it
}
感謝の
<
に動作します。それはうまくいった!私は実際にエラーを投稿しました。それはちょうど "error15"と言った。 – ChemicalRocketeerあなたの貧弱なエラー処理のおかげで'System.err.println(" Error "+ e.getMessage())'は多くの情報を出力しません。少なくとも 'e.printStackTrace()'を呼び出して、エラーの発生場所とエラーの種類を確認してください – Robin