I have 2 Arrays, both are 4*4 arrays. I want to copy 1 element from the first array and put it into the second array, then display the second array with the new element in it. However, I'm getting an error.
I'm using a deepToString call to print the Arrays. Below is my code:
public static void main(String [] args)
{
System.out.print("Enter a row and column # for your first selection?");
row = scan.nextInt(); //user enters row #
column = scan.nextInt(); //user enters column #
service.show(row, column); //row and column # passed as parameters
System.out.println(Arrays.deepToString(board1)); //this will display board1
//with the new element, leaving the rest of the elements untouched
}
Public void show(int row, int column)
{
Int a = row;
Int b = column;
board1[a][b] = board2[a][b]; //destination on left, source on right
//board1 is taking an element from index [a][b] in board2
}
The line board1[a][b] = board2[a][b]; is where I'm getting a "NullPointerException". I thought it was just an assignment statement to copy one element into another array. Is there a more efficient way to copy one element and display the new array? Does anybody have an idea on how to fix this?
board1andboard2?