1
// In my ViewModel that is setup to use Room I use the following in a function
// The dao returns a LiveData object and I call getValue() to get the value
{
    List<Item> items = (List<Item>) dao.loadAllByParentId(id).getValue(); // This is null
    deleteItems(items);
}

The application then throws an NullPointerException somewhere else which I have traced to this piece of code. I'm not too experience in Android so I know this may seem trivial for some of you, but please if you could help I would appreciate it.

jax
  • 728
  • 1
  • 11
  • 31
  • Can you update your post with your `deleteItems()` code? – Sammy T Feb 17 '20 at 02:13
  • That's irrelevant. The point is that items returns null after. Whether or not I call deleteItems or do anything else with the value, it will throw a NullPointerException. What I want to know is how to get the value that I know exists in the database. I believe it has to do with threading. It's just that I have minimal experience with android. – jax Feb 17 '20 at 02:28
  • This still gives very little context. Useful information might be how and when you're calling this function, how your Dao is set up, are you able to query other Dao functions (ie query the whole data set) with valid results? Otherwise all anyone can do is guess or assume there are no matching values for that query. – Sammy T Feb 17 '20 at 03:29
  • @SammyT I realize that more information like the ones you mentioned would be helpful. But I am not doing anything overly complex. As AI said, I have minimal experience with Android. Thus, I believe my problem is a common one made by beginners. You know, the equivalent of not using "equals" on String objects. I was hoping someone with more experience would be able to quickly identify a possible culprit. But, now I seem to have solved it myself. Thanks for the response though. – jax Feb 17 '20 at 06:54
  • 1
    https://stackoverflow.com/questions/48025008/livedata-object-keeps-being-null-after-getvalue-is-called?rq=1 – Iman Hamidi Feb 21 '20 at 01:22

0 Answers0