Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTom Finet
7,027 PointsStack overflow error, why?
I am developing a google app engine powered android app using endpoints and in the api which I am writing I keep getting stack overflow errors for no apparent reason.
So far here are the 2 methods in my endpoint api class:
@ApiMethod(name = "saveProfile")
public Profile saveProfile(@Named("userId") String userId,
@Named("firstName") String firstName,
@Named("lastName") String lastName,
@Named("birthday") String birthday) {
Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now();
if (profile == null) {
profile = new Profile(userId, firstName, lastName, birthday);
} else {
profile.updateProfile(firstName, lastName, birthday);
}
ofy().save().entity(profile).now();
return profile;
}
@ApiMethod(name = "getSuggestedFriends")
public List<Profile> getSuggestedFriends(@Named("userId") String userId) {
Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now();
if (profile != null) {
/**
* Queries for users with same last name as you (presumably family).
*/
Query<Profile> sameLastName = ofy().load().type(Profile.class).order("birthday");
sameLastName = sameLastName.filter("lastName =", profile.getLastName());
/**
* Gets the friends of your friends.
*/
List<Profile> suggestedFriends = new ArrayList<>(0);
for (Profile friend : profile.getFriends()) {
for (Profile friendOfFriend : friend.getFriends()) {
if (!profile.getFriends().contains(friendOfFriend))
suggestedFriends.add(friendOfFriend);
}
}
/**
* Merge the 2 lists into 1 list of suggested friends.
*/
for (Profile suggestedFriend : sameLastName) {
if (!profile.getFriends().contains(suggestedFriend))
suggestedFriends.add(suggestedFriend);
}
return suggestedFriends;
} else
return null;
}
Can someone offer some insight and a solution as to why this is happening?
Cheers.