How to use recyclerview in fragment?

614 Views Asked by At

I use Navigation Drawer in my Project and i want to use recyclerview too but my problem is when i use Navigation Drawer i should use Fragments too and i tried to use recyclerview in fragment ,but this error displayed in Logcat

06-14 21:56:29.376: E/AndroidRuntime(25109): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dmcoder.newsOfcoc/com.dmcoder.newsOfcoc.activity.ActivityMain}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference

And I'm sorry , my English is not very good

1

There are 1 best solutions below

0
On

There is no special hackery magic to use RecyclerView inside Fragment.

This error state that your RecyclerView object is null. You need to properly initialize it with findViewById. If you are using fragment you are doing on in the override of onViewCreated, you are supposed to inflate layout you wish to use.