Java Runtime Error
I am new to Java. I am trying to use objects as array but it is showing a runtime error as " Null pointer exception". This is my code : import java.util.*; class Students { String name; int id; double ptr; public void show() { System.out.println("ID : " + id + "Name : " + name + "Pointer " + ptr); } } public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Students s[] = new Students[4]; System.out.print("Enter name : "); s[0].name = sc.nextLine(); System.out.print("Enter ID number : "); s[0].id = sc.nextInt(); System.out.print("Enter Pointer of the student : "); s[0].ptr = sc.nextDouble(); System.out.println(s[0].name); } }