Search code examples
androidandroid-studiokotlindata-bindingandroid-databinding

Cannot find symbol class Data binding impl


Sorry I cannot post image directly to the post, because it said that I must have at least 10 reputation to post it.

I created an xml in android studio like this Xml

and created 2 variable inside view model like this

private val _loadingText = MutableLiveData<String>()
val loadingText: LiveData<String> = _loadingText

then implement the data binding like this into my dialog view

val dialogView = layoutInflater.inflate(R.layout.dialog_custom_loading, dialog_root)
    val binding = DialogCustomLoadingBinding.inflate(layoutInflater, dialogView as ViewGroup, false)
    binding.viewModel = viewModel
    loading = Dialog(this)
    loading.setContentView(binding.root)

but when i run the code, it shown an error like this

Error

and i dont know, how to solve it.. help me please..

UPDATE : when i run with --stacktrace i still dont know what error is this..

The expression 'viewModelLoadingText.getValue()' cannot be inverted, so it cannot be used in a two-way binding

Details: There is no inverse for method getValue, you must add an @InverseMethod annotation to the method to indicate which method should be used when using it in two-way binding expressions


Solution

  • You are using two-way databinding which is not correct in this place.

    Change android:text="@={viewModel.loadingText}" to android:text="@{viewModel.loadingText}"

    More information about the issue: Two-way databinding is used when you also want your data to be updated from UI. A case may be an EditText which posts its text to a MutableLiveData and sets its text from it. Check out the official documentation for more details.