• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a custom listview with data from databas

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
mainactivity.java



datamanager class



I get the following in logcat with a force clase


help!!!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic