Reputation: 25
I am currently creating a java application in which I have a 2d array which I want to get some data into.
I am creating the 2d array as such
String[][] addressData;
and then when I am trying to put data in I am using reference the exact position in the 2d array I want to enter the data into e.g
addressData[0][0] = "String Data";
The program compiles yet when I run I get a NullPointerException error. Am I using the wrong method to enter data into this 2d array?
Upvotes: 0
Views: 1231
Reputation: 8003
String[][] addressData - this is just declaration, you have to create actual object String[][] addressData = new String[size][size];
Btw, There is no 2d arrays in java String[][] is an array of arrays of strings
Upvotes: 10