User to User relations? Friend list android example

I am making app where I want users to add other users as friends. I have set up one to many relation for Users in my Users table and I am struggling with reading the friend list and updating it, here is my code and error messages :
How do I update the existing users, here is the code I use now:

 BackendlessUser user = Backendless.UserService.CurrentUser();
 ArrayList<BackendlessUser> friends = new ArrayList<BackendlessUser>();
 friends.add(userThatIwantToAdd);
 user.setProperty(BackendlessUserProperties.FRIENDS, friends);
Backendless.UserService.update(user, new DefaultCallback<BackendlessUser>(context) );


But for unknown reasons to me, I get this error

1. BackendlessFault{ code: '1007', message: 'Unable to save object - invalid data type for properties - friends. You can change the property type in developer console.' }

So can you please point me in the right direction, is it possible to add BackendlessUser object to others or do I have to make a column that remembers just their objectIds or something? I have the relation working with GeoPoints without any problems, I am not sure why this doesn’t work.
Second problem is getting the list of friends, here is the error I get.

 java.lang.Object[] cannot be cast to java.util.List<com.backendless.BackendlessUser>

And this is my code:

BackendlessUser user = Backendless.UserService.CurrentUser();
List<BackendlessUser> pendings = (List<BackendlessUser>) user.getProperty(BackendlessUserProperties.PENDINGS);

I tried to cast the Object[] but it doesn’t work. I also searched the support forum, and I have found this code snippet, that should solve the second problem, but it doesn’t even tough I have included it right after the initApp() call.

Backendless.Data.mapTableToClass("Users", BackendlessUser.class);

I am new to Backendless so it may be a stupid mistake or the api changed because this snippet is from a year ago, and that could be the reason why it doesn’t work. Note that autoLoad is checked for the friends column in Users table.

Hi Stevan,

I’m going to try to reproduce these problems. Could you please let me know the following:

    Did you get the backendless library from maven or from our website? Did you add the "friends" custom user property in console? (this is optional, you do not have to, if you didn't).
Regards, Mark
  1. I added backendless library as a .jar a few weeks ago.

  2. Yes, I added the custom property in console first.

Thanks, Stevan. We’re going to try to reproduce the problem and will report back. Meanwhile, just to make sure it is not something that has already been fixed. Could you please grab the latest jar from the link below and see if it makes any difference (click View Raw on the page to download):
https://github.com/Backendless/Android-SDK/blob/master/out/backendless.jar

I tried the latest .jar but it doesn’t seem to affect anything. I get the same errors.

Any help ?
Is there a guide or something for this or something similar wih user relations to user in documentation?

Stevan,

I added a task for the dev team to reproduce the problem and report back. There is a queue of tasks and we will get to it. I apologize we cannot solve all the problems at once, it does take time.

Regards,
Mark

Ok, thanks Mark.

Hi, Stevan!

I just want to let you know that we’ve reproduced this problem and working on the fix.
Internal task number is 11693.
best regards,
Alex Navara

Thanks Alex, please write here when the fix is done.

Hello, Stevan!

This issue has been fixed and would be released soon.
best regards,
Alex

That’s great news! Thank you very much.

Could you give me info about when the new release will be published?

We estimate it will be in the first half of this week.

So did you publish the release with fix for this?

Hi Stevan, the release has slipped to Monday. My apologies for that, we had all the intentions to get it out this week.

Hi, Stevan!

The fix has been released. Can you try again?
best regards,
Alex

Yes, can you just point me where to download the new jar ?

Hi Stevan,

The latest one is here: https://github.com/Backendless/Android-SDK/blob/master/out/backendless.jar

It will be deployed to our website later today.

Regards,
Mark

It works now :slight_smile: I will continue developing my app and report if I get more problems related to this here. But it sems ok now, thanks a lot!