There is a class called PageInfo which is like this:
I assume the max size of arrays is 5.
public static class PageInfo {
String username;
PageInfo[] followings;
Post posts[];
PageInfo (String username,PageInfo[] followings,Post[] posts) {
this.username = username;
this.followings = followings;
this.posts = posts;
}
public int getPostLength () {
int cnt = 0;
for (int i = 0; i < 5; i++) {
if (posts[i] != null )
cnt++;
}
return cnt;
}
public int getFollowingLength () {
int cnt = 0;
for (int i = 0; i < 5; i++) {
if (followings[i] != null )
cnt++;
}
return cnt;
}
}
and there is a Post class like:
public static class Post {
String cation;
int id;
PageInfo[] usersLiked;
Post (String caption, int id, PageInfo[] usersLiked) {
this.cation = caption;
this.id = id;
this.usersLiked = usersLiked;
}
}
I want to declare a user with constructor like:
PageInfo[] allusers = new PageInfo[5];
allusers[0] = new PageInfo("John", "54321", new PageInfo[5], new Post[5]);
allusers[0].followings[0] = allusers[1];
allusers[0].posts[0] = new Post("John Post", 100, new PageInfo[5]);
The "getPostLength" works well. but when "GetFollowingLength" returns me 0. why? and how to fix it? how can i add "followings" to the allusers[x] later in the project?
It seems that "followings" hasn't been initialized yet and the're still Null. how can i properly initalize them?