Нулевая ошибка отображается, когда я хочу обновить свою базу данных номеров
Привет, ребята . это мой код.
class ChosseAddress : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val vl = inflater.inflate(R.layout.choose_address_layout, container, false) val animsec: Animation = AnimationUtils.loadAnimation(vl.context, R.anim.anim_for_btn_zoom_out) vl.button_back_choose_address.setOnClickListener { it.startAnimation(animsec) childFragmentManager.beginTransaction() .replace(R.id.choose_address_container, HamburgerFragment()) .commit() } val database = DataBaseRoom(requireContext()) val repository = RepositoryCart(database) val factoryRoom = FactoryRoom(repository) val viewmodel: ViewModelRoom = ViewModelProvider(ViewModelStoreOwner { viewModelStore }, factoryRoom).get(ViewModelRoom::class.java) vl.edit_address.setOnClickListener { val mDialogView = LayoutInflater.from(context).inflate(R.layout.alertfialog_costume, null) val dialogtext = LayoutInflater.from(context).inflate(R.layout.edit_alert_txt, null) val mBuilder = AlertDialog.Builder(vl.context) .setView(mDialogView) .setCustomTitle(dialogtext) val show = mBuilder.show() mDialogView.edit_manually.setOnClickListener { show.dismiss() val mydialogview = LayoutInflater.from(context).inflate(R.layout.alertdialog_manually, null) val mytextcustome = LayoutInflater.from(context).inflate(R.layout.custome_title_editmanually, null) val alert = AlertDialog.Builder(vl.context) alert.setView(mydialogview) .setCustomTitle(mytextcustome) val myalert = alert.show() mydialogview.btn_submit_address.setOnClickListener { val edittxt: String = mydialogview.edit_txt_change_address.text.toString() if (edittxt.isEmpty()) { Toast.makeText( vl.context, "لطفا آدرس رو وارد کرده و دکمه ثبت رو فشار دهید ", Toast.LENGTH_SHORT ).show() } else { val address : String address = edittxt viewmodel.updatetxt(Editaddress(null , address)) myalert.dismiss() viewmodel.getalledit().observe(viewLifecycleOwner , Observer { val edit = it.toString() Toast.makeText(context , "$edit" , Toast.LENGTH_SHORT).show() }) } } mydialogview.cancel_btn.setOnClickListener { myalert.dismiss() } } } return vl } }
Итак, когда я хочу обновить свою базу данных номеров, это дает мне ошибку, которая :
Комната.Editaddress.toString()' по ссылке на нулевой объект
Что я уже пробовал:
I tried So things like debugging : the edit text returns the value but when i want to show it with observer give me error . In my Room DAO i don't have declar any insert method and just declared an update and getall data method . there is no problem with no defining of insert method. Cause i only want to update the data not to insert any thing . anyone can help with this ? Thank's in Advanced