Yooouuri Yooouuri - 2 months ago 10
Android Question

Expected resource type to be one of id, id

activity_criminals_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_criminals_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.yourivanmill.csi.CriminalsList">

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>


CriminalsList.java

package com.yourivanmill.csi;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class CriminalsList extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_criminals_list);

//final String[] criminals = getResources().getStringArray()
final String[] crimials = { "Charles Zwolsman", "Etienne Urka", "Cor Van Hout" };

ListView listView = (ListView) findViewById(R.id.activity_criminals_list);

listView.setAdapter(
new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
crimials
)
);
}
}


The following line

ListView listView = (ListView) findViewById(R.layout.activity_criminals_list);


give a an error: Expected resource type to be one of id, id ...

In another activity when i use the findViewById method it works...

My api version is 23!

Answer

In this line you are passing the id of the whole layout:

ListView listView = (ListView) findViewById(R.id.activity_criminals_list);

And you try to init ListView with it's ID, whose name is different from the layout name:

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

ListView listView = (ListView) findViewById(R.id.list);
Comments