Right now I am having trouble filling an array with spaces. Whenever I use the array fill method I keep getting an exception. Right now I excluded the rest of the code and only included the ones that causes problems. Here it is. Note I am a beginner to java so don’t get angry if this is too simple of a question. I have searched here and could not find anything.
public class board
{
public static void main(String args[])
{
char board [][] = new char [6][7];
int column=0;
int row=0;
java.util.Arrays.fill(board,' ');
}
}
The exception says
Exception in thread “main” java.lang.ArrayStoreException:
java.lang.Character
at java.util.Arrays.fill(Arrays.java:2710)
at java.util.Arrays.fill(Arrays.java:2685)
at board.main(board.java:26)
Arrays.fillexpects a single-dimensional array, you’re passing in a jagged array.Instead, do this:
or this: