Problem using AsyncCallback

Hi!
I`m ttrying to save the data using AsyncCallback. The table is created, but the columns are not. What am i doing wrong?

Pet pet = new Pet();
pet.setAndroid_id(android_id);
pet.setIsADog(isADog);
pet.setName(petName);
Log.e(TAG, "Pet is "+ pet.getAndroid_id()+" "+ pet.getName()+" "+ pet.isADog());
// save object asynchronously
Backendless.Persistence.save( pet, new AsyncCallback<Pet>() {
public void handleResponse(Pet petDB)
{
Log.e(TAG, "new Contact instance has been saved "+ petDB.getAndroid_id()+" "+ petDB.getName()+" "+ petDB.isADog());
}
public void handleFault( BackendlessFault fault )
{
Log.e(TAG, "an error has occurred: "+ fault.getCode()+" " +fault.getDetail()+ " " + fault.getMessage());
}
});

The log i get is:new Contact instance has been saved null null false

Hi Gidi,

Could you please post the source code for the Pet class?

Regards,
Mark

public class Pet {


    private long id;
    private List<String> vaccines;
    private List<Long> dates;
    private List<String> comments;
    private String name;
    private boolean isADog;
    private String android_id;


    public Pet(long id, List<String> vaccines, List<Long> dates, List<String> comments, String name, boolean isADog) {
        this.id = id;
        this.vaccines = vaccines;
        this.dates = dates;
        this.comments = comments;
        this.name = name;
        this.isADog = isADog;
    }


    public Pet (String name, String android_id, boolean isADog){
        this.name = name;
        this.android_id = android_id;
        this.isADog = isADog;
    }


    public Pet() {
    }


    public String getAndroid_id() {
        return android_id;
    }


    public void setAndroid_id(String android_id) {
        this.android_id = android_id;
    }


    public long getId() {
        return id;
    }


    public void setId(long id) {
        this.id = id;
    }


    public List<String> getVaccines() {
        return vaccines;
    }


    public void setVaccines(List<String> vaccines) {
        this.vaccines = vaccines;
    }


    public List<Long> getDates() {
        return dates;
    }


    public void setDates(List<Long> dates) {
        this.dates = dates;
    }


    public List<String> getComments() {
        return comments;
    }


    public void setComments(List<String> comments) {
        this.comments = comments;
    }


    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public boolean isADog() {
        return isADog;
    }


    public void setIsADog(boolean isADog) {
        this.isADog = isADog;
    }
}

I just saved an instance of your Pet class in my app and got the following schema:

http://support.backendless.com/public/attachments/88dc2745138853d272d1d9bac7509eea.jpg</img>

The properties which you have as collections (vaccines, dates, comments) will not save properly as Backendless supports one-to-many collections between complex types only. That is you will not be able to save a “Pet to List of Strings” collection. Instead, you could wrap each comment into a separate object (say Comment):

public class Comment
{
  public String commentText;
}

and change the “comments” property in the Pet class to:

private List<Comment> comments;

That will store everything.

Regards,
Mark

Hi Mark! Thank you for your answer. I didn`t try to save my lists yet (i will save them as strings, using Gson). As you can see in my original question, i was unable to save a Pet with android_id, name, and boolean isADog. And that what i got after:

When and where did you get backendless.jar from?

i`ve added it as a dependency: compile ‘com.backendless:android:3.0.3’, but now i see that my libs folder is empty…

Could you download it from the link below and try again?

https://github.com/Backendless/Android-SDK/tree/master/out

thnx mate! Solved the problem!!