0
private var _binding: FragmentSignUpPageBinding? = null
private val binding get() = _binding!!

private lateinit var firestore: FirebaseFirestore
private lateinit var storage: FirebaseStorage
private lateinit var auth: FirebaseAuth

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    auth = Firebase.auth
    firestore = Firebase.firestore
    storage = Firebase.storage
}

There is a initialized elements from Firebase

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View {
    _binding = FragmentSignUpPageBinding.inflate(inflater,container,false)
    val name = binding.nameText.text.toString()
    val surname = binding.surnameText.text.toString()
    val email = binding.emailText.text.toString()
    val password = binding.passwordText.text.toString()
    val button = radioButton.isChecked
    val button2 = radioButton2.isChecked

    if (name.equals("")|| surname.equals("")){
        Toast.makeText(requireActivity(),"Error",Toast.LENGTH_LONG).show()
    }
    return binding.root

There is a viewBinding in Fragment, values i will use and checks to be done before proceeding to the next page.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    signUpButton.setOnClickListener {
        val action = SignUpPageFragmentDirections.actionSignUpPageFragmentToSignCalculatorFragment()
        Navigation.findNavController(it).navigate(action)
    }
}

And finally fragment code that will allow me to switch to the next page.

The problem is when i click the signUpButton, program is crashing.

Attempt to invoke virtual method 'boolean android.widget.RadioButton.isChecked()' on a null object reference

And there is a error about radio buttons. When i remove these buttons values, app is running. But Toast message is starts as soon as the page is opened. It does not check whether any data has been entered.

So how can i solve these buttons error and Toast message problem?

KKot
  • 161
  • 3
  • 9

0 Answers0