This is a trivial question, but my Java is rusty and it's got me stumped; I am getting a null-pointer exception. It may be obvious what I am trying to do based on the code below - but I will explain...
I need an array of objects and I don't want to create another file. For this trivial project, I do not want getters and setters. I have seen an example similar to below that uses a linked list based on a class that is located inside of another class. But, I am more proficient with arrays than linked lists, so I want to use arrays.
public class Ztest {
Stuff[] st = new Stuff[2];
public Ztest(){
}
class Stuff{
public String x;
public boolean y;
public Stuff(){}
}
public static void main(String args[]){
Ztest test = new Ztest();
test.st[0].x = "hello";
test.st[0].y = true;
test.st[1].x = "world";
test.st[1].y = false;
System.out.println(test.st[0].x);
System.out.println(test.st[0].y);
System.out.println(test.st[1].x);
System.out.println(test.st[1].y);
}
}