• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Creating a custom listview with data from databas  RSS feed

 
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!!!
 
Bartender
Posts: 4179
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.
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!