Why my code generate NullPointerException?

<>

This question already has an answer here:

Answers


You create an array which takes Students as its input but you never estuary put one in there. So the students[0].setName("name") never actually sets the name property of an object. The consequence is, you can't access it either.

You already pointed out the solution: iteratively filling your array with students although you just print the student's attributes in your for loop so far. Using something like students[i] = new Student() would give you an array with empty students which you can also fill after you created each one.


Need Your Help

ExtenderControlBase.cs not found when I am using the calendarExtender Ajax Control

c# asp.net ajax

I got this error when I am trying to add an Ajax calendar. I have downloaded the Ajax Control Toolkit from the CodePlex (I tried the new release (dec 2013 and the previous one). I added a new tab...

Failure while unicast data from kernel to user space via netlink

c module linux-kernel netlink

I am new to kernel development and have a problem in uni casting the data from the kernel space to user space over netlink sockets. send_nat() function is to be called from a kernel module to writ...