I’m trying to save an object in a data table with two 1to1 relations with the user table. However when I run the following code to add them the new object is added to the table without the relations and the callback returns a java.lang.NullPointerException.
Insights insight = new Insights();
insight.setFromUser(user);
insight.setToUser(contacts.get(position));
insight.setType(type);
insight.setMessage(message);
Backendless.Data.of(Insights.class).save(insight, new AsyncCallback<Insights>() {
@Override
public void handleResponse(Insights response) {
//TODO: broadcast success
//TODO: add insight to saved list
}
@Override
public void handleFault(BackendlessFault fault) {
//TODO: broadcast failure
Log.e("Save insight", "failure");
Log.e("Save insight", fault.getDetail());
}
});
Is there someone who could help me understand where the problem is?
Thank you, that was probably one of the problems, however even when I change the code this way there still the problem that the object is saved but the program enters in the handleFault with the same exception and so the relations are not added.
Insights insight = new Insights();
insight.setType(2);
insight.setMessage(message);
Backendless.Data.of(Insights.class).save(insight, new AsyncCallback<Insights>() {
@Override
public void handleResponse(Insights response) {
Log.w("save","ok");
AsyncCallback<Integer> callback = new AsyncCallback<Integer>() {
@Override
public void handleResponse(Integer response) {
}
@Override
public void handleFault(BackendlessFault fault) {
}
};
BackendlessUser
List<BackendlessUser> fromList = new ArrayList<BackendlessUser>();
fromList.add(user);
Backendless.Persistence.of( Insights.class ).setRelation(response, "fromUser", fromList, callback );
List<BackendlessUser> toList = new ArrayList<BackendlessUser>();
fromList.add(contacts.get(position));
Backendless.Persistence.of( Insights.class ).setRelation(response, "toUser", toList, callback );
//TODO: broadcast success
//TODO: add insight to saved list
}
@Override
public void handleFault(BackendlessFault fault) {
//TODO: broadcast failure
Log.e("Save insight", "failure");
Log.e("Save insight", fault.getDetail());
}
});