-1

I am getting a resource not found issue in an app I am playing with, the id does exist in the view, and the correct view is being used. I have deleted the R file and regenerated but that hasn't helped. It compiles and appears the resource is found but at run time it errors when attempting to set text in the textview. Hopefully some one can point out what is causing this.

Here is the adapter code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    SongHolder songHolder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
        row = inflater.inflate(mLayoutResourceId, parent, false);

        songHolder = new SongHolder();
        songHolder.txtSongId = (TextView)row.findViewById(R.id.songid);
        songHolder.txtName = (TextView)row.findViewById(R.id.name);
        songHolder.txtArtist = (TextView)row.findViewById(R.id.artist);
        songHolder.txtAlbum = (TextView)row.findViewById(R.id.album);
        songHolder.txtNotes = (TextView)row.findViewById(R.id.notes);

        row.setTag(songHolder);
    }
    else
    {
        songHolder = (SongHolder)row.getTag();
    }

    ClassSong song = mSongs.get(position);
    //###############THE FOLLOWING LINE IS WHERE THE ERROR OCCURS###############
    songHolder.txtSongId.setText(song.getSongID());
    songHolder.txtName.setText(song.getName());
    songHolder.txtArtist.setText(song.getArtist());
    songHolder.txtAlbum.setText(song.getAlbum());
    songHolder.txtNotes.setText(song.getNotes());

    if(song.getAlbum() == "" || song.getAlbum() == null)
        songHolder.txtAlbum.setVisibility(View.GONE);
    else 
        songHolder.txtAlbum.setVisibility(View.VISIBLE);

    if(song.getNotes() == "" || song.getNotes() == null)
        songHolder.txtNotes.setVisibility(View.GONE);
    else 
        songHolder.txtNotes.setVisibility(View.VISIBLE);
    return row;
} 

The xml for the view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gat"
android:padding="0dip">

<LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/name" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#FFFFFF"
        android:textSize="18sp"/>
    <TextView android:id="@+id/songid"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:visibility="gone"
        android:textColor="#FFFFFF"
        android:textSize="18sp"/>
    <TextView android:id="@+id/artist" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#517789"
        android:textSize="15sp"/>

    <TextView android:id="@+id/album" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:textColor="#517789"
        android:textSize="12sp"/>
</LinearLayout>

<LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/notes" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#517789"
        android:textSize="12sp"/>
</LinearLayout>

</LinearLayout>

and the code from the list activity that calls the adapter:

private void fillData() {

    ClassSong song = new ClassSong(this);
    ClassSongListAdapter adapter = new ClassSongListAdapter(this, R.layout.song_row, song.getAllSongs(this));
    setListAdapter(adapter);



}

Also, when picking up the view in the holder it is found and has a value that is not null obviously. So it appears that the textview is found when added to the view holder but not when I attempt to set a value to it, if I comment out the songid line the other assignments work just fine. Anyone have any ideas?

Thanks.

collusionbdbh
  • 701
  • 1
  • 6
  • 18
  • Could you try disable the view recycling? an what error do you get, null pointer exception? – Kirill Kulakov Nov 18 '13 at 21:01
  • Thanks, @Ridcully was correct, I was trying to set an int into a TextView without converting it to a string so rather than automatically attempting to convert it to a string it was looking for a resource with that id. – collusionbdbh Nov 18 '13 at 21:31

1 Answers1

2

I supppose, song-ID is an integer: Then convert it to a string and you'll be fine:

songHolder.txtSongId.setText(song.getSongID()+"");

Explanation: There are two setText() methods, one expecting a String parameter, is used to set text directly, the other, expecting an int parameter is actually expecting a resource id like R.string.app_name and if your song-ID is an integer, you've accidently invoked the later version which is expecting a resource id, hence the error.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • That solves the issue, thanks a lot. I knew it was going to be something small like that I was overlooking. The error that says resource not found made it so confusing. Thanks again. – collusionbdbh Nov 18 '13 at 21:29