I know that i have not written a catch block yet.(reason?, but i think it's actually not the problem; the attributes of the "Game" class are perfectly changeable)
I always get an IOException when i try to call the setName method in Player (even if I set "name" in Player to public and change it directly).
public class game{
protected static int amountPlayers;
protected static Player[] playerList = new Player[amountPlayers];
public static void main (String[] args) throws IOException{
//Scanner reader = new Scanner(System.in);
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String input;
System.out.println("new round? (1 for yes; enter for no):");
int boo = Integer.parseInt(br.readLine());
if (boo == 1) {
Rounds.setNew(true);
} // end of if
if (Rounds.getNew() == true) {
//SavingManagement.createFile();
System.out.println("# of players:");
int amount = Integer.parseInt(br.readLine());
setAmountPlayers(amount);
} // end of if
for (int i = 0; i < amountPlayers; i++) {
System.out.println("Name player No. " + (i + 1) + ":");
input = br.readLine();
playerList[i].setName(input);
} // end of for
}
public class Player {
protected static int score;
protected static String name = "";
public static void setName(String input) {
name = input;
}
}
Assuming that you are providing the valid size in
amountPlayers, by writing the following statement you are just creating the Player array and not initializing it.Before you can use
setName(), you'll have to initialize the array as follows:OR you can do something like this: