I am pretty new to java but i have to initialize an 2d-array size n, in this example 10. After initialization i want to check the diagonal entries if they are false, and if set them to true. After i want to return value of i.
This is what i coded:
First of all initialization of the array:
public static void init(int n) {
boolean friendship[][] = new boolean[n][n];}
and after i tried this:
public static int addUser(String name) {
int id=0;
for ( int i=0;i<friendship.length;i++) {
if ( friendship[i][i] = false) {
friendship[i][i] = true;
id = i;
}
}
return id;
}
Sadly its throwing:
Exception in thread "main" java.lang.NullPointerException
at x.SocialNetwork.addUser(SocialNetwork.java:18)
at x.SocialNetwork.main(SocialNetwork.java:53)
What can i do to fix this?
PS: Sorry for bad english and formatting.