2

I've created a dummy project to understand Card-Based Layout. Unfortunately, I am getting cannot resolve symbol errors on RecyclerView. I'm quite new to programming and can't understand what went wrong. Dependencies are added to build file:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
}

While I'm trying to create a field in Activity I'm getting cannot resolve symbol errors on RecyclerView.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

    public class MainActivity extends AppCompatActivity {

        RecyclerView recyclerView;

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

3 Answers3

0

Try

  • File > Sync Project with Gradle Files

.

Now Remove and start typing the RecyclerView again, it should show up.

Akshay
  • 73
  • 8
0

when you want to use a class you should import its library.

in this case, you haven't import recyclerview library. to fix this just change your activity code to :

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView; //recyclerview library

    public class MainActivity extends AppCompatActivity {

        RecyclerView recyclerView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    }
houman.sanati
  • 1,054
  • 3
  • 18
  • 34
0

You did not import the RecyclerView class, so there's no way your compiler would know what you are talking about. Simply add this line to your import statements:

import android.support.v7.widget.RecyclerView;

Your code should run fine after that.


PS:
To make your programming experience easier, you can just auto-import all the classes you need. Click here to learn more.

I hope this helps.. Merry coding!

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69