Why my code generate NullPointerException?<>
This question already has an answer here:
You create an array which takes Students as its input but you never estuary put one in there. So the students.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.