android.content.res.ResourceNotFoundException:String resource ID #0x2 in onListItemClicked

final int row_index = participant.getColumnIndex(HRADbAdapter.participant_id);
final int participant_id = participant.getInt(row_index);

TextView participant_id_tv = (TextView )new_participant_view.findViewById(R.id.patient_id);
participant_id_tv.setText(participant_id);  //this is the line that caused the above exception.

At the beginning, I was thinking it’s because participant_id_tv is null. but after looking at my laoyout file, R.id.patient_id is clearly a valid resource id, with <TextView android:id=”@+id/patient_id”…./>

It turns out it’s because when I pass an integer to setText, android thinks I am passing a resource id and tries to find resource. what I need is to explicitly convert int to String as below:

participant_id_tv.setText(Integer.toString(participant_id));

Now it’s okay. simple.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s