Hello, first time this year with Java and seems like I've forgotten some basic concepts about OOP I'm coding a simple ascii-based flat-file database as a homework and I didn't get very far before first problems appeared. Exception in thread "main" java.lang.NullPointerException at Yearclass.ask(Register.java:103) at Register.main(Register.java:7) Could somebody be kind enough to tell me, what's wrong with the following code ?
hi roni in YearClass's Students u did allocated memory for the array but not for the individual elements which are again objects of Student class. so in the ask() method's for loop when you invoke method on students[i].ask() it gives u null pointer as students is allocated but not students[i]. somewhere u shd have, for(int i=0; i < MAX; i++) students[i] = new Student(); u know.. regards maulin
Joined: Jul 23, 2002
Originally posted by Maulin Vasavada: hi roni so in the ask() method's for loop when you invoke method on students[i].ask() it gives u null pointer as students is allocated but not students[i].
Thank you Maulin. It works fine now. Looks like I should brush up with some basic OOP concepts. - Roni
subject: NullPointerException - could somebody explain why ?