Relations Object saving issue (both Sync request and Async Request)

While saving relation object we are facing issue. The exception we are getting is this…
Process: com.example.parulgarg.newbackendless, PID: 9468
java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.Class java.lang.Object.getClass()’ on a null object reference
at com.backendless.utils.ReflectionUtil.getFieldValue(ReflectionUtil.java:39)
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:164)
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:167)
at com.backendless.Persistence.save(Persistence.java:109)
at com.example.parulgarg.newbackendless.MainActivity$1.run(MainActivity.java:93)
at java.lang.Thread.run(Thread.java:818)
What actually happens…

  1. Data saves on server but in application we get error.
  2. Crashes in bothe the cases Whether the request is sync or Async .
    Here is my code…
    String appVersion = “v1”;
    Backendless.initApp(this, “39626EF0-6A9C-EE25-FF97-EEFAE63FA900”, “3DC96B3F-E86E-5F64-FFCB-147E9D757700”, appVersion);
    // owner…
    Address address = new Address();
    address.setState(“state1”);
    address.setStreet(“street1”);
    address.setCity(“city1”);
    Student owner = new Student();
    owner.setName(“sagbd”);
    owner.setRno(1);
    owner.setEmail(“first@gmail.com”);
    owner.setAddress(address);
    // contact1…
    Address Contact1Address = new Address();
    Contact1Address.setCity(“city2”);
    Contact1Address.setState(“state2”);
    Contact1Address.setStreet(“street2”);
    Student student1 = new Student();
    student1.setAddress(Contact1Address);
    student1.setName(“student1_name”);
    student1.setEmail(“email1@gnail.com”);
    student1.setRno(2);
    // contact2…
    Address Contact2Address = new Address();
    Contact2Address.setCity(“city3”);
    Contact2Address.setState(“state3”);
    Contact2Address.setStreet(“Street3”);
    Student student2 = new Student();
    student2.setName(“Amit”);
    student2.setEmail(“amit@gmail.com”);
    student2.setRno(14);
    student2.setAddress(Contact2Address);
    // prepare list…
    List<Student> students = new ArrayList<Student>();
    students.add(student1);
    students.add(student2);
    final PhoneBook phoneBook = new PhoneBook();
    phoneBook.setOwner(owner);
    phoneBook.setStudentList(students);
    Thread th = new Thread(new Runnable() {
    @Override
    public void run() {
    Object object = Backendless.Persistence.save(phoneBook);
    Log.e(“response”,"response "+object.toString());
    Log.e(“response”,"response "+object.getClass().getName());
    }
    });
    th.start();
    I am sharing the link of whole project zip, you can import it using Android studio IDE…Here is the link of dropbox link…Dropbox - Error - Simplify your life

Hi Akash,

Thanks for submitting this, it was an interesting problem. A simple fix for this problem is to rename the following columns:

    In table PhoneBook, you have column "Owner", rename it to "owner" In table Student, you have column "Address", rename it to "address"
Alternatively, if you want to keep columns the same way they are now, you can get rid of getter/setters for the owner field in PhoneBook and make the field public:
public Student owner;

Same change in the Student class - get rid of getAddress/setAddress and make the field public:

public Address address;

This this helps.

Regards,
Mark

Thanks Mark for the suggestion, I will try this fix and will let you know if come across the same crash again.

I have a similar problem to this, the object is saved on the server but I get an exception thrown.
I have a table for a user profile (UserProfile), which is a property of User table and is autoload.
Then I have another table that holds other information (UserLocation), and it has a relationship to User table (1:1).
When I set the User to the UserLocation table and try to save it, even though the data is saved on the server I get the error complaining about non existing properties.

BackendlessException{ code: ‘IllegalArgumentException’, message: ‘userProfile’ }
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:205)
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:167)
at com.backendless.Persistence$3.handleResponse(Persistence.java:162)
at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NoSuchFieldException: userProfile
at java.lang.Class.getDeclaredField(Class.java:886)
at com.backendless.utils.ReflectionUtil.getField(ReflectionUtil.java:65)
at com.backendless.utils.ReflectionUtil.getField(ReflectionUtil.java:71)
at com.backendless.utils.ReflectionUtil.getFieldValue(ReflectionUtil.java:39)
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:161)
at com.backendless.FootprintsManager$Inner.duplicateFootprintForObject(FootprintsManager.java:167)
at com.backendless.Persistence$3.handleResponse(Persistence.java:162)
at com.backendless.async.message.AsyncMessage$ResponseHandler.handle(AsyncMessage.java:64)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

When I disable the autoload from the User table then the object is saved with no exception thrown.
Does that mean that when I have autoload enabled, I can not set the table as a property of another?

Regards,

George

Hi George,

Could you please try with the latest library build from here:
https://github.com/Backendless/Android-SDK/blob/master/out/backendless.jar

Regards,
Mark

Doing a full rebuild right now and I will get back to you.

Yeap that did it. Thank you Mark.

Regards,

George