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.
Shalom