-8

Here i want to print the value of Brick[][] matrix. But it is showing me the output as java.lang.Nullpointerexception https://i.stack.imgur.com/Yi5BW.png

Mr. KK
  • 1
  • 2
  • 1
    Welcome to StackOverflow. Please provide a [MCVE](https://stackoverflow.com/help/mcve) whenever possible so people can help with specific elements of your code and attempts. – Mat Feb 26 '19 at 16:16

1 Answers1

0

The line highlighed is not where the error occured. You didnt initialize the array, so:

brick[i][j] = val;

throws a NullPointerException. Additionaly you're starting the iteration from 1 (int i=1) instead of 0, see java arrays.

    public Brick(int row, int col) {
        brick = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                brick[i][j] = Integer.parseInt( i + "" + j );
            }
        }
    }
Lones NB
  • 51
  • 1
  • 4