Подтвердить что ты не робот

Ошибка android.content.res.Resources $NotFoundException: Файл из ресурса макета типа xml ID # 0x102000a

Эй, я пытаюсь создать дизайн для списка, который выглядит (и в основном ведет себя как) журнал вызовов, как показано здесь:

alt text

Для этого я загрузил исходный код, и я изучаю его, чтобы узнать, какой класс и файл xml реализуют его.

И я нашел эти два xml файла 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" />

а другой 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"
/>

И моя деятельность такова:

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();
        }
    });

}

}

И затем я попытался запустить его на эмуляторе Android, а затем LogCat возвратил ошибку, подобную этой:

Вызвано: java.lang.RuntimeException: ваш контент должен иметь ListView, чей атрибут id "android.R.id.list"

Итак, внутри recent_calls_list_item.xml я сказал следующее:

<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>

И теперь с этим объявлением я попытался запустить в эмуляторе, но LogCat возвращает еще одну ошибку:

android.content.res.Resources $NotFoundException: Файл с идентификатором ресурса типа xml # 0x102000a

Итак, мой вопрос: почему это происходит? И если у вас есть другое решение для реализации такого вида, я пытаюсь.

Спасибо.

4b9b3361

Ответ 1

установите идентификатор вашего listView в

android:id="@id/android:list"

Я не знаю,

android:id="@android:id/list"

работает правильно

Ответ 2

У меня была та же проблема. Я настраивал текст следующим образом:

statusView.setText(firstVisiblePosition);

Проблема заключалась в том, что firstVisiblePosition был целым числом. Компилятор не жаловался. Исправлено с помощью

statusView.setText(""+firstVisiblePosition);

Ответ 3

Звучит слабо, но если вы используете Eclipse, попробовали ли вы очистить и перестроить свой проект? Это фиксировало аналогичную проблему, с которой я столкнулся.

Ответ 4

Я также могу решить проблему, преобразовывая значение Integer в String при использовании:

name.setText(name_value_needs_to_be_string);

где name является TextView.

Ответ 5

Компилятор интерпретирует ваш аргумент int как ссылку на ресурс и предполагает, что вы вызываете:

 public final void setText (int resourceId)

но ваше намерение состояло в том, чтобы позвонить

 public final void setText (CharSequence text)

Чтобы исправить это, выполните следующие действия:

myTextView.setText(Integer.toString(myIntegerValue));

Ответ 6

Я решил эту проблему, скопировав XML файл из каталога layout-land в layout (или наоборот). Некоторые устройства имеют режим пейзажа по умолчанию, другие - портрет. Если этот файл не существует в этом режиме, он выдает это исключение.