I am currently working my college assignment. I've already stuck in this problem for awhile, can somebody point out my mistakes. Much appreciated! I created a class that return a list of game, when I trying to populate my recycle view data. This error is shown:
2020-01-09 13:27:58.937 20456-20456/com.example.android.navigation E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.navigation, PID: 20456 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigation/com.example.android.navigation.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property gameAdapter has not been initialized
class TitleFragment : Fragment() {
private lateinit var gameAdapter: GameRecyclerAdapter
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view: View = inflater!!.inflate(R.layout.fragment_home, container, false)
val mRecyclerView = view.findViewById(R.id.rv_game_list) as RecyclerView
val linearLayoutManager = LinearLayoutManager(activity)
mRecyclerView.setLayoutManager(linearLayoutManager)
val data = DataSource.createDataSet()
gameAdapter.submitList(data)
return view
}
}
package com.example.android.navigation.models
class DataSource {
companion object{
fun createDataSet(): ArrayList<GameList>{
var list = ArrayList<GameList>()
list.add(
GameList(
title = "Testing1",
body = "dummy data of testing1",
username = "alex"
)
)
list.add(
GameList(
title = "Testing2",
body = "dummy data of testing1",
username = "chris"
)
)
list.add(
GameList(
title = "Testing3",
body = "dummy data of testing1",
username = "wong"
)
)
list.add(
GameList(
title = "Testing4",
body = "dummy data of testing1",
username = "long"
)
)
list.add(
GameList(
title = "Testing5",
body = "dummy data of testing1",
username = "james"
)
)
return list
}
}
}