All of sudden I start getting this error, and I am not getting idea why if anyone just let me know where this error is, will be enough helpful. As much I am able to get is t
I had the same error. I had two issues.
You may need to add
implementation 'androidx.room:room-ktx:2.2.5'
I had deleted a file that was referenced as a member in one of the activity_xml files. The error never gave me any clue until I changed it to annotationProcessor instead of kapt, then it pointed out the error, I found the file, and sure enough I had a reference to a file that I no longer used and was deleted. I removed this data reference from the xml and it cleared it all up. Then I put it back to kapt.
This method occurs to me everything there is a problem with Room database and Coroutines, even spell mistakes. Lastly was when trying to return a single value with a Flow after inserted column, by: Flow<Long> from DAOs classes.
It should be a suspend function and only Long type to return after inserted column.
These problems are ambiguous sometime, so try to read all the Build Output messages, the message that help me was: error: Not sure how to handle insert method's return type.
If you have upgraded to classpath 'com.android.tools.build:gradle:4.0.0' Replace it previous version
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
}
And Change gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4- all.zip`
I had the same problem. In my case the problem was about Database. i had to change this line of code
@Database(entities = [SearchedLocation::class, FavoriteLocation::class], version = 1)
I added another table in Database but forgot to add table in the line above.
In my case it was because I was not implementing Observable in my ViewModel. I added an EditText to the constraint layout with android:text="@={addProductViewModel.inputProductName}"
Once I implemented Observable in my ViewModel class the error was gone
ViewModel
class AddProductViewModel (
private val repository: ProductRepository,
private val context: Context
): ViewModel(), Observable {
@Bindable
val inputProductName = MutableLiveData<String>()
fun addProduct() {
//inputProductName.value
}
override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
TODO("Not yet implemented")
}
override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
TODO("Not yet implemented")
}
}
Complete example for MVVM Databinding using Fragments
Layout - add_product.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" >
<data class=".AddProductBinding">
<variable
name="addProductViewModel"
type="com.rao.iremind.AddProductViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editTextTextProductName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Product name"
android:inputType="textPersonName"
android:text="@={addProductViewModel.inputProductName}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
AddProductFragment
class AddProductFragment: Fragment() {
private lateinit var binding: AddProductBinding
private lateinit var addProductViewModel: AddProductViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.add_product, container, false)
val dao = SubscriberDatabase.getInstance(requireActivity().applicationContext).productDAO
val repository = ProductRepository(dao)
val factory = AddProductViewModelFactory(repository, requireActivity().applicationContext)
addProductViewModel = ViewModelProvider(this, factory).get(AddProductViewModel::class.java)
binding.addProductViewModel = addProductViewModel
binding.lifecycleOwner = this
val view = binding.root
return view
}
}
AddProductViewModel
class AddProductViewModel (
private val repository: ProductRepository,
private val context: Context
): ViewModel(), Observable {
@Bindable
val inputProductName = MutableLiveData<String>()
fun addProduct() {
//inputProductName.value
}
override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
TODO("Not yet implemented")
}
override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
TODO("Not yet implemented")
}
}
Hope this helps R
I got the same issue, so I tried to get more information, by doing
gradle->app->Tasks->Build->assemble
After this I got exact error saying "Error while annotation processing". I checked my recently tweaked DAO class and found that one of the method return type was not defined.
//Before
@Query("SELECT countryName FROM country_table WHERE countryCode= :code")
fun getCountryNameForCode(code: String)
//After
@Query("SELECT countryName FROM country_table WHERE countryCode= :code")
fun getCountryNameForCode(code: String): String