Realm request request results in nullpointerexception error

I am trying to make a request in an area. But I still get a null pointer exception in equalTo ("id", 38)

This is an exception:

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference at io.realm.RealmQuery.getColumnIndices(RealmQuery.java:140) at io.realm.RealmQuery.equalTo(RealmQuery.java:199) at es.treenovum.paedocuments.services.OfflineService$WidgetOpsNewest.loadTags(OfflineService.java:340) at es.treenovum.paedocuments.services.OfflineService$WidgetOpsNewest.doInBackground(OfflineService.java:228) at es.treenovum.paedocuments.services.OfflineService$WidgetOpsNewest.doInBackground(OfflineService.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) ... 3 more 

An exception occurs on the equalTo line here:

 Category categoryResult = realm.where(Category.class) .equalTo("id", category.getId()) .findFirst(); 

int category.getId () is not null or empty. the kingdom is not.

If the first time I started the application, db is empty. Will this cause this? Should you return null or 0 instead of throwing an exception?

EDIT: added category class. All getters and setters created by eclipse.

 import io.realm.RealmObject; import io.realm.annotations.RealmClass; import com.google.gson.annotations.SerializedName; @RealmClass public class Category extends RealmObject { @SerializedName("id") private int id; @SerializedName("text") private String text; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getText() { return text; } public void setText(String text) { this.text = text; } } 
+5
source share

Source: https://habr.com/ru/post/1212692/


All Articles