Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RecyclerView Error

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);
}
like image 602
Tak3r07 Avatar asked Nov 09 '14 16:11

Tak3r07


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

like image 168
mt0s Avatar answered Sep 18 '22 11:09

mt0s


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

like image 22
Olof Avatar answered Sep 18 '22 11:09

Olof


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

like image 41
imbalind Avatar answered Sep 18 '22 11:09

imbalind


Just upgrade to SDK 22 and the problem is fixed

like image 44
Omar Ceron Avatar answered Sep 19 '22 11:09

Omar Ceron