Home » Android » java – Android RecyclerView Error

java – Android RecyclerView Error

Posted by: admin June 15, 2020 Leave a comment

Questions:

today I was trying to use the new android RecyclerView.
I have created a new Project with a blank activity and added the following to its layout:

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

In gradle build dependencies I have added:

compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.android.support:cardview-v7:21.+'

But the activity_main.xml rendering still shows me the following error:

Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.RecyclerView (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE  Exception Details java.lang.UnsupportedOperationException: Unsupported Service: accessibility   at com.android.layoutlib.bridge.android.BridgeContext.getSystemService(BridgeContext.java:465

I don’t seem to find a solution myself in the web since everyone says “implement the following dependencies in your gradle build: …” which i have already added.

Can anyone provide a solution?

Regards
Tak3r07

Edit:
onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
How to&Answers:

I think that with RecyclerView you have at least to set the layout manager.

If you read the docs here :

In contrast to other adapter-backed views such as ListView or GridView, RecyclerView allows client code to provide custom layout
arrangements for child views. These arrangements are controlled by the
RecyclerView.LayoutManager. A LayoutManager must be provided for
RecyclerView to function.

You can try after instantiating the RecyclerView to set the LayoutManager like that :

recyclerView.setLayoutManager(new LinearLayoutManager(this));

( later change it to a LayoutManager that fits better your needs )

Answer:

This seems to be a bug in Android SDK 21. If you upgrade to SDK 22 the problem should disappear.

Answer:

I know the topic is a bit old, but the problem still persists and it’s a known bug.

Anyhow the bug seems to be close to get a patch:

https://code.google.com/p/android/issues/detail?id=72117

Answer:

Just upgrade to SDK 22 and the problem is fixed

Answer:

Just change Api level on the top of the screen in your xml viewer and make it 21 api level it will be work . hope it will help you.

Answer:

Add this line in your build.gradle file under dependencies block

implementation 'com.android.support:recyclerview-v7:25.1.0'

Answer:

Hi hope this will help you
You have to remove scrollbars attribute from your view