Witam
Kod klasy Ziomek:
package cwiczenia;
import java.util.*;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
/**
*
* @author Kamil
*/
public class Ziomek {
private String imie;
private String nazwisko;
private Indeks indeks;
int ile;
public Ziomek(int ile){
imie = "brak";
nazwisko = "brak";
this.ile = ile;
indeks.oceny = new int[5];
indeks.przedmioty = new String[5];
}
public void podaj() throws FileNotFoundException{
try (PrintWriter zapis = new PrintWriter("ilosc.txt")) {
Scanner wpisz = new Scanner(System.in);
System.out.println("podaj imie: ");
imie = wpisz.nextLine();
System.out.println("podaj nazwisko: ");
nazwisko = wpisz.nextLine();
System.out.println("podaj przedmioty: ");
for(int i=0;i<indeks.oceny.length;i++){
indeks.oceny[i]= wpisz.nextInt();
zapis.print(indeks.oceny[i]);
}
}
}
}
Kod klasy indeks:
* and open the template in the editor.
*/
package cwiczenia;
import java.util.*;
/**
*
* @author Kamil
*/
public class Indeks {
public String przedmioty[];
public int oceny[];
}
Chcac wpisac zawartosc to tablicy z klasy indeks ktorej uzywam w klasie Ziomek wyskakuje mi blad:
Exception in thread "main" java.lang.NullPointerException
at cwiczenia.Ziomek.podaj(Ziomek.java:37)
at cwiczenia.Cwiczenia.main(Cwiczenia.java:15)