I'm getting a compilation build error when I add a MutableLiveData object to my view model in my Android Studio project. I'm not calling getUser() or setUser() anywhere yet and I added the exact same object to a different view model in my project and haven't gotten an error, so I'm not sure what the problem is.
Error:
error: Parceler: Unable to find read/write generator for type androidx.lifecycle.MutableLiveData<com.example.demometvtest1.User> for com.example.demometvtest1.RegisterViewModel.user
RegisterViewModel.java:
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
@Parcel
public class RegisterViewModel extends ViewModel {
public MutableLiveData<User> user = new MutableLiveData<>();
public void setUser(String user) {
return user;
}
public MutableLiveData<User> getUser() {
this.user.setValue(user);
}
}
The problem is the annotation @Parcel
: you are trying to automatic generate writeToParcel()
& createFromParcel()
and the annotation processor doesn't find a read/write implementation for MutabileLiveData (that it's not parcelable).
Remove the annotation, make the class implement the parcelable interface and make your own implementation of parcelable metods writeToParcel()
& createFromParcel()
if you need It or simply remove the annotation.