I think I am making a really basic mistake but after playing around for an hour I cant work this out. I create an array in one method and try and call it in the main method, however I keep getting a null pointer exception when referencing the array from the main method. My class is:
public class test {
public static String[][] Data;
public static void createArray() {
System.out.println("Test 2");
String[][] Data = new String[2][4];
Data[0][0] = "13CG43"; //CD ID
Data[0][1] = "POP"; //Type
Data[0][2] = "12.99"; //Price
Data[0][3] = "5"; //Stock
//Second row
Data[1][0] = "293DD3"; //CD ID
Data[1][1] = "HIP"; //Type
Data[1][2] = "14.99"; //Price
Data[1][3] = "2"; //Stock
}
public static void main(String[] args) {
try {
System.out.println("Test1");
createArray();
System.out.print("Test3 " + Data[0][0]);
} catch(Exception e) {
System.out.println("Error");
}
}
}
Thanks,