Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving data from table for a search bar

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to retrieve values from a table for a search bar.The search bar works fine when i use predefined values in a string array.But crashes when i use a database

The search bar code


The adapter code



The datamanager code


The logcat


The code for the search bar works fine when i used predefined values for the array but fails at this step

please help!!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You define String[] str as an instance variable, and immediately try to assign it the results of dm.retrieveproducts(). You don't initialize the dm variable until the onCreat() method is called. So you get into a situation where str is trying to use the variable dm at instance creation time, but dm is not yet initialized, so it is null, so you get a NullPointerException.

You need to move the assignment to str to some point after you initialize dm, which probably means putting it in the onCreate() method, or if it takes time then moving it to a different thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic