Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

setText in onBindViewHolder returning null

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got the Firebase database structure as shown in Image1. My code to retrieve all the children under the "Orders" node is as follows:



This is the AdminOrdersViewHolder class:



The problem with the above code is it returns all null values (as shown in Image2). In other words, model.getName(), model.getPhone(), model.getAddress(), model.getCity, model.getState, model.getPin(), model.getTotalAmount, model.getOrderDate & model.getOrderTime() return null values. Can someone please help me out with this?

Please note that in the first image, if the node "112226042020" is not present, the above code runs fine but the null values are returned after the node "112226042020" has got added. What could be the issue please?

Thanks...
DB.jpg
Image1
Image1
8162373c-a783-4371-b502-67fa634982f4.jpg
Image2
Image2
 
Ranch Foreman
Posts: 95
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick guess: Order of execution.
TLDR: At the time when the view is constructed the model hasn't populated yet. So, figure out the order (and timing) when the data are fetched and put into the model and change your code so it happens befor the view calls the getter.
 
Arpan De
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bob for your suggestion but I guess that is not the issue. There are 2 reasons why I am saying so:

Firstly, as already stated in my post, the null values creep up only when the node "112226042020" is there but if it is not there, setText gets the correct values from Firebase. Secondly, there is a button as well in the AdminOrdersViewHolder class. When this button is clicked & the user selects one of the 2 options, then that item gets deleted from Firebase (even though all of them are nulls). So I don't think that is the issue. Any other suggestion please???

Thanks once again....
 
Bob Winter
Ranch Foreman
Posts: 95
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
debug debug debug - or in other words: what makes you so sure about that your assumptions that my idea is incorrect? have you really debugged it or do you just guess?
sadly I don'T know much about android development - but when something in a gui shows up as null it's most often of two reasons:
1) wrong order of execution / bad timing
2) gui updated from the wrong thread (not the EDT)
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic