0

In my application I am experiencing the same sort of error as found here or here however the suggested solution of cleaning the Eclipse project isn't working for me. Specifically I have a custom ListView adapter that is attempting to load two TextViews from its layout file, the first TextView is found no problem but the second throws the ResourceNotFound exception and crashes the application.

Layout File

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/roomNameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="16dp"
        android:text="Room name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/roomNumText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/roomNameText"
        android:layout_below="@+id/roomNameText"
        android:text="Room number"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

Adapter

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        m = new ViewHolder();
        convertView = mInflater.inflate(R.layout.room_row, null);
        convertView.setTag(m);
    } else {
        m = (ViewHolder) convertView.getTag();
    }

    m.name = (TextView) convertView.findViewById(R.id.roomNameText);
    m.name.setText(rooms.get(position).getName());
    m.roomNumber = (TextView) convertView.findViewById(R.id.roomNumText);
    m.roomNumber.setText(rooms.get(position).getRoomNumber());
    return convertView;

}

I have also tried editing R.java just to force Eclipse to regenerate the file but that also doesn't work. Really not sure what else to try since I have another adapter that is basically the same but for different data that works perfectly. Also ViewHolder is a static class that is just a container class for any views being accessed (have to use it according to coding style) in case anyone was wondering.

Community
  • 1
  • 1
jhorvat
  • 385
  • 3
  • 14

1 Answers1

4

change

   m.roomNumber.setText(rooms.get(position).getRoomNumber());

with

   m.roomNumber.setText(String.valueOf(rooms.get(position).getRoomNumber()));

in your code you are using the setText(int stringId) which looks up inside R.string to retrive the stringId parameter . Also I would change your getView this way:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
    m = new ViewHolder();
    convertView = mInflater.inflate(R.layout.room_row, null);
    m.name = (TextView) convertView.findViewById(R.id.roomNameText);
    m.roomNumber = (TextView) convertView.findViewById(R.id.roomNumText);
    convertView.setTag(m);
} else {
    m = (ViewHolder) convertView.getTag();
}


m.name.setText(rooms.get(position).getName());
m.roomNumber.setText(String.valueOf(rooms.get(position).getRoomNumber()));
return convertView;

}
Blackbelt
  • 156,034
  • 29
  • 297
  • 305