在android应用程序中找不到资源错误

在android应用程序中找不到资源错误,android,textview,custom-adapter,Android,Textview,Custom Adapter,我在玩的应用程序中遇到资源未找到问题,该id确实存在于视图中,并且正在使用正确的视图。我已经删除了R文件并重新生成,但这没有帮助。它编译并显示资源已找到,但在运行时尝试在textview中设置文本时出错。希望有人能指出原因 以下是适配器代码: @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; SongHolder son

我在玩的应用程序中遇到资源未找到问题,该id确实存在于视图中,并且正在使用正确的视图。我已经删除了R文件并重新生成,但这没有帮助。它编译并显示资源已找到,但在运行时尝试在textview中设置文本时出错。希望有人能指出原因

以下是适配器代码:

@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;
} 
视图的xml:

<?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>
此外,在保持架中拾取视图时,会发现它的值明显不为null。因此,文本视图似乎是在添加到视图持有者时找到的,但在我尝试为其设置值时却找不到,如果我注释掉songid行,其他赋值就可以正常工作。有人有什么想法吗


谢谢。

我支持,歌曲ID是一个整数:然后将其转换为字符串,您就可以了:

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

说明:有两个
setText()
方法,一个需要
String
参数,用于直接设置文本,另一个需要
int
参数,实际上需要资源id,如
R.String.app\u name
,如果您的歌曲id是整数,您意外调用了需要资源id的更高版本,因此出现了错误

你能试着禁用视图回收吗?你会得到什么错误,空指针异常?谢谢,@Ridcully是正确的,我试图将int设置为TextView,而没有将其转换为字符串,因此它没有自动尝试将其转换为字符串,而是在寻找具有该id的资源。这解决了问题,非常感谢。我知道它将是一个小东西,就像我正在俯瞰的一样。表示未找到资源的错误使它变得如此混乱。再次感谢。
songHolder.txtSongId.setText(song.getSongID()+"");