0
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Tech[] std=new Tech[5];
        int i;
        for(i=0;i<5;i++)
        {
            System.out.println("Enter Name of Student");

               String Name;

               Scanner scanIn = new Scanner(System.in);
               Name = scanIn.nextLine();
               scanIn.close(); 
            std[i].setName(Name);
            System.out.println(std[i].name);
        }

    }

}

Exception in thread "main" java.lang.NullPointerException at Main.main(Main.java:16)

Jens
  • 67,715
  • 15
  • 98
  • 113
  • 1
    well for a start `std` is an array of `Tech` not `String` and they have not been instantiated (only defined) - maybe `std[i] = new Tech(name);` – Scary Wombat Aug 18 '17 at 06:44
  • 1
    Take care of the Java naming convention. variable names should start with lowercase character – Jens Aug 18 '17 at 06:45

0 Answers0