The AlertDialog(Material) crashes when tries to read the editText content.
The AlertDialog:
MaterialAlertDialogBuilder(activity)
.setTitle(title)
.setMessage(message)
.setView(R.layout.dialog_settings_entry)
.setPositiveButton(getString(R.string.text_change)) { dialog, which ->
etUserInput.hint = message
sgr = etUserInput.text.toString() // << crashes here
dialog.dismiss()
}
.setNegativeButton(getString(android.R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
.show()
On clicking the positive button results as follows:
java.lang.IllegalStateException: etUserInput must not be null
at com.home.profile.SettingsFragment$buildAlertDialog$1.onClick(SettingsFragment.kt:332)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
The etUserInput is simple editText in a seperate layout. Unsure the crash reason. Would appreciate any insight into it or any helpful Material samples.
etUserInput
? I think you forget to initialize it – TributeetUserInput
inflated in the current screen? – StrontianetUserInput
inflated via Kotlin synthetic import. – NumidiaetUserInput.text?.let{ sgr = it.toString() }
but no luck! – Numidia