scanner i NullPointerException

0

W klasie Main tworze tablice typu klasy Student o podanym przez użytkownika rozmiarze.Kiedy biorę się za wypełnianie tablicy wywala błąd NullPointerException w linijce stud[i].nazwisko=sc.next();

import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
       
        Scanner sc=new Scanner(System.in);
        System.out.println("Podaj liczbę studentów");
        int ls=sc.nextInt();
        Student stud[]=new Student[ls];
        
        for(int i=0; i<ls; i++){  
            
            System.out.print("Podaj dane studenta(nazwisko,imię,, nr. albumu, rok, średnia) ");
          
            stud[i].nazwisko=sc.next();
            stud[i].imie=sc.next();
            stud[i].album=sc.nextLong();
            stud[i].rok=sc.nextInt();
            stud[i].srednia=sc.nextDouble();
        }
    
        for(int i=0; i<ls; i++){
            stud[i].wyswietl();
        }
 
    }

}

Wygląda to tak,jakby tablica nie została utworzona,chyba że błąd tkwi w czymś innym.

0

A jak wygląda klasa Student?

0

Tablica została utworzona, ale jej elementy nie.

        for(int i=0; i<ls; i++){  
            stud[i] = new Student();
            System.out.print("Podaj dane studenta(nazwisko,imię,, nr. albumu, rok, średnia) ");

1 użytkowników online, w tym zalogowanych: 0, gości: 1