Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x102000a

Hey, I'm trying to create a design for a list that looks like (and mostly behaves like) the call log, like shown here:

alt text

For this I downloaded the source code and I'm studying it for know what class and xml file implement it.

And I found this two xml files recent_calls_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="7dip"> 

<com.psyhclo.DontPressWithParentImageView
    android:id="@+id/call_icon" android:layout_width="wrap_content"
    android:layout_height="match_parent" android:paddingLeft="14dip"
    android:paddingRight="14dip" android:layout_alignParentRight="true"

    android:gravity="center_vertical" android:src="@android:drawable/sym_action_call"
    android:background="@drawable/call_background" />

<include layout="@layout/recent_calls_list_item_layout" />

and the other is recent_calls_list_item_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<View android:id="@+id/divider"
    android:layout_width="1px"
    android:layout_height="match_parent"
    android:layout_marginTop="5dip"
    android:layout_marginBottom="5dip"
    android:layout_toLeftOf="@id/call_icon"
    android:layout_marginLeft="11dip"
    android:background="@drawable/divider_vertical_dark"
/>

<ImageView android:id="@+id/call_type_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="4dip"
/>

<TextView android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/divider"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="8dip"
    android:layout_marginLeft="10dip"

    android:textAppearance="?android:attr/textAppearanceSmall"
    android:singleLine="true"
/>

<TextView android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="36dip"
    android:layout_marginRight="5dip"
    android:layout_alignBaseline="@id/date"

    android:singleLine="true"
    android:ellipsize="marquee"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textStyle="bold"
/>

<TextView android:id="@+id/number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/label"
    android:layout_toLeftOf="@id/date"
    android:layout_alignBaseline="@id/label"
    android:layout_alignWithParentIfMissing="true"

    android:singleLine="true"
    android:ellipsize="marquee"
    android:textAppearance="?android:attr/textAppearanceSmall"
/>

<TextView android:id="@+id/line1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@id/divider"
    android:layout_above="@id/date"
    android:layout_alignWithParentIfMissing="true"
    android:layout_marginLeft="36dip"
    android:layout_marginBottom="-10dip"

    android:textAppearance="?android:attr/textAppearanceLarge"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:gravity="center_vertical"
/>

And my activity is this:

public class RatedCalls extends ListActivity {

private static final String LOG_TAG = "RecentCallsList";
private TableLayout table;
private CallDataHelper cdh;
private TableRow row;
private TableRow row2;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.recent_calls_list_item);
    Log.i(LOG_TAG, "calling from onCreate()");

    cdh = new CallDataHelper(this);
    table = new TableLayout(getApplicationContext());
    row = new TableRow(getApplicationContext());

    startService(new Intent(this, RatedCallsService.class));
    Log.i(LOG_TAG, "Service called.");
    fillList();

}

public void onResume() {

    super.onResume();
    fillList();

}

public void fillList() {

    List<String> ratedCalls = new ArrayList<String>();
    ratedCalls = this.cdh.selectTopCalls();

    setListAdapter(new ArrayAdapter<String>(RatedCalls.this,
            android.R.id.list, ratedCalls));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Toast.makeText(getApplicationContext(),
                    ((TextView) view).getText(), Toast.LENGTH_LONG).show();
        }
    });

}

}

And then I tried to run it on the android emulator, and then it the LogCat returned an error like this:

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

So inside the recent_calls_list_item.xml I declared this:

<ListView android:id="@android:id/list" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_x="1px"
    android:layout_y="1px">
</ListView>

And now with this declared I tried to run in the emulator, but the LogCat returns another error:

android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x102000a

So, my question is, why is this happening? And if you have another solution for implement a view like this I'm trying.

Thanks.

like image 997
rogcg Avatar asked Jan 11 '11 14:01

rogcg


4 Answers

I had the same problem. I was setting the text like this:

statusView.setText(firstVisiblePosition);

The problem was that firstVisiblePosition was an integer. Compiler didn't complain. Fixed it by

statusView.setText(""+firstVisiblePosition);
like image 60
ile Avatar answered Oct 27 '22 20:10

ile


Sounds lame but if you are using Eclipse, have you tried cleaning and rebuilding your project? That fixed a similar problem I was having.

like image 35
anisbet Avatar answered Oct 27 '22 19:10

anisbet


I am also able to solve the problem by converting the Integer value to String while using:

name.setText(name_value_needs_to_be_string);

where name is a TextView.

like image 33
Khushboo Avatar answered Oct 27 '22 20:10

Khushboo


The compiler interprets your int argument as a resource reference and assumes you are calling:

 public final void setText (int resourceId)

but your intention was to call

 public final void setText (CharSequence text)

To fix it, do like so:

myTextView.setText(Integer.toString(myIntegerValue));
like image 32
onosendai Avatar answered Oct 27 '22 18:10

onosendai