I want to write a good chat application with bottom navigation using Fragments. In ChatsFragment.kt I got a problem: enter image description here
My fun onCreateView() in ChatsFragment:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
usersRecycler.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
var userlist = ArrayList<User>()
userlist.add(User("Squirrel", "https://wampi.ru/image/RjQ3yNw"))
userlist.add(User("Adam", "https://wampi.ru/image/RjQ3yNw"))
var userAdapter = UserAdapter(requireActivity(), userlist)
usersRecycler.adapter = userAdapter
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_chats, container, false)
}
Exception on usersRecycler.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
I read a lot of solutions like: "replace "this" to requiredActivity() or requiredContext()", but nothing helped, throwing out this error: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
I also wanted replace Fragments on Activity as bottom navigation. Would that be the wrong decision?
How can I resolve this problem? Help me, android developers, please...