I've created a custom class called Person. Now I want to use the person class the same way you can with a String or int class, by turning them into a table when I create a variable with the person class.
Person[] persons = new Person[3];
But when I do it like this, I get the error: NullPointerException
.
Is there any way to fix it, so I can use the person class as a list?
This is my person class:
class Person{
//Definerer navn og posisjonen.
String navn;
String[] interesser = new String[4];
//Funksjonen for aa sette navn.
void settNavn(String navn){
this.navn = navn;
}
//Funksjonen for aa sette interesser.
void settInteresser(String interesser, int index){
this.interesser[index] = interesser;
}
//Funksjonen for aa hente navnet.
String hentNavn(){
return navn;
}
//Funksjonen for aa hente interessene.
String hentInteresser(int index){
return interesser[index];
}
}