i declared the variable and initialized it but i still get this error
Code:
//Main
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
// Scanner input=new Scanner(System.in);
// Random rnd=new Random();
StuInfo();
}
public static void StuInfo()
{
Scanner io=new Scanner(System.in);
Random rnd=new Random();
System.out.println("How many students are there?");
student[] stu = new student[io.nextInt()];
for (int i = 0; i < stu.length; i++)
{
stu[i].age = 5;
}
}
}
//Student
public class student {
int age;
double[] grade;
String name;
}
Inputs:
4
Error:
exception in thread "main" java.lang.NullPointerException
at Main.StuInfo(Main.java:39)
at Main.main(Main.java:12)