I am working on a simulation and I get an error every time! I tried evreything but i cant find an answer. This is the code: Person.java:
package School;
import java.util.Random;
public class Person {
private Random rng;
private String Name;
private String[] Friends;
private int Hobby;
private boolean IsDitch;
public Person(String Name, String[] Friends, int Hobby, boolean IsDitch){
int aof = rng.nextInt(20);
this.Name = Name;
this.Friends = Friends;
Friends = new String[aof];
this.Hobby = Hobby;
if(rng.nextInt(10) == 0){
IsDitch = true;
}else{
IsDitch = false;
}
this.IsDitch = IsDitch;
}
public boolean getIsDitch(){
return IsDitch;
}
public int getMaxFriends(){
return Friends.length;
}
public String getName(){
return Name;
}
}
Interaction.java:
package School;
public class Interaction {
public static void main(String[] args){
String[] g;
g = new String[2];
g[0] = "Natasha";
g[1] = "Fill";
Person mrt = new Person("Adam",g,2,false);
System.out.println(mrt.getName());
}
}
The error I am getting:
Exception in thread "main" java.lang.NullPointerException
at School.Person.<init>(Person.java:12)
at School.Interaction.main(Interaction.java:9)