• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Creating a custom listview with data from databas

Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using this tutorial for creating a custom listview from the database http://www.learn2crack.com/2013/10/android-custom-listview-images-text-example.html

But i modified the mainactivity such that the names and the image id's are retrieved from the database

datamanager class

I get the following in logcat with a force clase

Posts: 4179
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As always, a NullPointerException is being thrown because you are using an variable which doesn't point to an object - it instead has a null value. In your case, we can find out where using the stack trace:

The problem is on line 41 of the MainActivity class, in the getID() method. Line 41 looks like this: id[i]=getResources().getIdentifier(str[i] , "drawable", getPackageName());. There are a couple of objects used on that line, but the system ones (the Resources and package name) can't be null. This leaves the id array and the str[] array. I am not sure if str[] can be null (I would have to read your datamanager class I think, but for id[]:

Yup, that can null because you assign it to null, and it will never be anything but null since you never assign any other value to it. Create an appropriate array and assign it to the id variable.
    Bookmark Topic Watch Topic
  • New Topic