Daniele
Daniele

Reputation: 4343

Android: Expected resource of type id

I'm having a strange problem in Android Studio.

I have got my activity_chords_list.xml file with a RecyclerView inside it that looks like this:

<android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/chords_recycler"
    android:layout_below="@+id/layout_top"
    android:layout_alignParentStart="true"
    android:layout_marginTop="50dp" />

But in my onCreate() method it isn't recognised:

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

    chordsList = (RecyclerView) findViewById(R.layout.chords_recycler);

and I get the following two errors:

Any idea on how to fix it?

Upvotes: 0

Views: 2443

Answers (2)

Lino
Lino

Reputation: 6160

I think you should use this:

 chordsList = (RecyclerView) findViewById(R.id.chords_recycler);

Upvotes: 3

antonio
antonio

Reputation: 18242

Change

android:id="@id/chords_recycler"

for

android:id="@+id/chords_recycler"

From the documentation:

The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

And you need to access it using R.id.chords_recycler:

chordsList = (RecyclerView) findViewById(R.id.chords_recycler);

Upvotes: 3

Related Questions