IllegalStateException: RecyclerView is null inside of Fragment within NavigationDrawer activity
You have not initialized the RecyclerView in MainFragment.kt
file. You have to initialize it before the below line:
mainMenu.layoutManager = LinearLayoutManager(this.context)
You can initialize the RecyclerView by the below line:
var mainMenu = findViewById(R.id.mainMenu) as RecyclerView
You have to change it as per your need.
For anyone that follow the brilliant clue of @Avijit Karmakar, getting in count another discussion, (RecyclerView error: No adapter attached; skipping layout) I had to include :
class WikiFragment : Fragment() {
val paginas: ArrayList<String> = ArrayList()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
var listItems : View = inflater.inflate(R.layout.fragment_wiki, container, false)
var rv_frag_wiki = listItems.findViewById<View>(R.id.rv_frag_wiki) as RecyclerView
rv_frag_wiki.layoutManager = LinearLayoutManager(this.context)
rv_frag_wiki.adapter = PaginasAdapter(paginas, this.context)
return listItems
Since you are using kotlin you can have advantage of synthetics where you don't need to do var rv_frag_wiki = listItems.findViewById<View>(R.id.rv_frag_wiki) as RecyclerView
Rather import synthetics via plugin Step 1 :
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Step 2 :
Import sythetic in MainFragment
import kotlinx.android.synthetic.main.content_menu.*
//
Step 3 :
Finally in MainFragment
Shift this code of recyclerView here
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
rvList.layoutManager = LinearLayoutManager(context,
LinearLayoutManager.VERTICAL, false)
rvList.adapter = academyAdapter
}