0

I am creating and trying to save a table using active android but for some reason the object fails to save. The error that I get is

java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference

Upon debugging the decompiled Model.class file I observed that an exception occurs while executing the following statement

(Please note that the below line is from the decompiled Model.class file of activeandroid)

long entityId1 = ((Model)e).getId().longValue();

It fails and the above said exception occurs. In the catch block I observe that for all non-primitive type fields the mId is non null, but for the field where the exception occurs the mId is null. I tried to search the web but could only find one line about mId.

ActiveAndroid automatically creates another auto-increment ID column. This is mId.

Then why does it fail to do so in this case. Does somebody have an idea? Thanks !!

varunkr
  • 5,364
  • 11
  • 50
  • 99

1 Answers1

0

OK I found the answer.

From codepath I found that

The problem is that This is because ActiveAndroid needs you to save all objects separately. Before saving a tweet for example, be sure to save the associated user object first. So when you have a tweet that references a user be sure to user.save() before you call tweet.save() since storing the user requires the local id to be set and assigned as the foreign key for the tweet.

Thus I had to save my non primitive type object field first before saving the object.

varunkr
  • 5,364
  • 11
  • 50
  • 99