Skip to content Skip to sidebar Skip to footer

Why Am I Getting An Error When I Populating A Custom Listview?

I'm using a custom listview and I'm getting the next error. Why?? In the Log setence I receive the data well, but for some reason it crashes. CLASS public class ListViewCustomClose

Solution 1:

Change

holder.tv_id_closeit.setText(closeItListModelArrayList.get(position).getId());

to

holder.tv_id_closeit.setText(String.valueOf(closeItListModelArrayList.get(position).getId()));

Most probably closeItListModelArrayList.get(position).getId() returns an int and when you pass it to setText Android will call method setText(int resID) instead of setText(CharSequence text)

So now Android will try to find the value corresponding to closeItListModelArrayList.get(position).getId() and when it does not find a value will a ResourceNotFoundException is thrown

Solution 2:

Replace

 holder.tv_id_closeit.setText(closeItListModelArrayList.get(position).getId());

By

 holder.tv_id_closeit.setText(""+closeItListModelArrayList.get(position).getId());

Solution 3:

Probably this

closeItListModelArrayList.get(position).getI‌​d()

returns a Integer value. And you cannot set int value directly to a textview.

Use String.valeuOf(intvalue)

holder.tv_id_closeit.setText(String.valueOf(closeItListModelArrayList.get(position).getId()););

setText does take int as a param but it looks for a Resource with the id mentioned. If not found you get ResourceNotFoundException.

What you require is setText that takes charactersequence as a param.

Solution 4:

SOLVED.

Thank you all. The problem is that I need to convert a INT to a STRING to set on a textview.

Change

holder.tv_id_closeit.setText(closeItListModelArrayList.get(position).getId());

to

holder.tv_id_closeit.setText(String.valueOf{closeItListModelArrayList.get(position).getId()));

Post a Comment for "Why Am I Getting An Error When I Populating A Custom Listview?"