This, seemingly simple construct, has me baffled. I've searched forums, the net, and my books, and I can't figure out it, although I am certain this is a very basic error.
I've defined my own class (MyTable) that is a simple data structure. I declare an array of them, but when I go to initialize them, I get a nullpointerexception right off the bat.
What is my idiotic error?
I've defined my own class (MyTable) that is a simple data structure. I declare an array of them, but when I go to initialize them, I get a nullpointerexception right off the bat.
What is my idiotic error?
Code:
public class TestClassArray {
public static void main(String[] arg) {
int periods = 5 ;
MyTable[] tab = new MyTable[periods] ;
for ( int i = 0 ; i < periods ; i++ ) {
tab[i].age = 22 ;
tab[i].month = "Jan" ;
tab[i].balance = 100.99 ;
}
}
}
class MyTable {
int age ;
String month ;
double balance ;
}