Tried to post the entire project here, but moderator said no. Apparently we're not allowed to post large volumes of code, just small snippets?
The project is 3 classes (StudentRecordExample.java[MAIN], StudentRecord.java,Student.java), which have been modified from the original MyStudentRecordExampleProject so its a bit bulky and could do with a lot of streamlining, but I figure it should work anyways. As said the error I'm getting is: Exception in thread "main" java.lang.NullPointerException at StudentRecordExample.main(StudentRecordExample.java:35) Java Result: 1 I used the 'new' keyword to create an instance of a Student object like so in StudentRecordExample.java: Student anna = new Student(); Then to set the name variable for object anna of class Student, I used: anna.studentRecord.setName("Anna"); which as I understand it gets method setName from class studentRecord. Do I have to explicitly link classes Student and StudentRecord some how for this to work? BTW this line of code where I set anna's name variable is highlighted when I click on the error, and is on line 35. On May 14, 6:00 pm, Nic Fox <f...@nicfox.com> wrote: > Without seeing your code it's hard to say. > > So you've used the 'new' keyword to make an instance of a Student > object? > E.g. Student anna = new Student(); > > And then you use something like: > anna.name = "Anna"; > > If you've done those things then it could be an issue with variable > scope perhaps? > > On 14/05/2010, at 11:47 PM, JKay wrote: > > > > > I keep getting the following error when I run my program: > > > Exception in thread "main" java.lang.NullPointerException > > at StudentRecordExample.main(StudentRecordExample.java:35) > > > I looked up what java.lang.NullPointException is in the API and found > > this: > > > "public class NullPointerException > > extends RuntimeException > > > Thrown when an application attempts to use null in a case where an > > object is required. These include: > > > * Calling the instance method of a null object. > > * Accessing or modifying the field of a null object. > > * Taking the length of null as if it were an array. > > * Accessing or modifying the slots of null as if it were an array. > > * Throwing null as if it were a Throwable value. > > > Applications should throw instances of this class to indicate other > > illegal uses of the null object." > > > Which as far as I understand means that I'm trying to do something > > with a null object. Said object is object anna of class Student, and > > the method on the line that is throwing the exception is me attempting > > to set the name variable for anna to "Anna" > > > Any ideas? > > > James > > > --> To post to this group, send email > > tojavaprogrammingwithpass...@googlegroups.com> To unsubscribe from this > > group, send email tojavaprogrammingwithpassion+unsubscr...@googlegroups.com > > For more options, visit this group > > athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en > > --To post to this group, send email > tojavaprogrammingwithpass...@googlegroups.comto unsubscribe from this group, > send email tojavaprogrammingwithpassion+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en