I use Android architecture components and tried to instantiate viewmodel and Observe data from LiveData. But im getting the following error :
ActivationFragment.clas:
@OnClick(R.id.btn_activation)
public void onEvaluateClick(Button v) {
maActivationCode = etActivation.getText().toString();
mActiationViewModel.getsatusCode(maActivationCode).observe(this, new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean aBoolean) {
}
});
}
ActivationViewModel class:
public class ActivationViewModel extends ViewModel{
public ActivationRepository activationRepository;
public ActivationViewModel(ActivationRepository activationRepository) {
this.activationRepository = activationRepository;
}
public LiveData<Boolean> getsatusCode(String activationCode) {
return (LiveData<Boolean>) activationRepository.getStatusCode(activationCode);
}
}
ActivationRepository class:
public class ActivationRepository {
public MutableLiveData<Boolean> status;
public MutableLiveData<Boolean> getStatusCode(String activationCode) {
status.setValue(Boolean.valueOf(false));
return status;
}
Update your function like this..
public class ActivationRepository {
public MutableLiveData<Boolean> status = new MutableLiveData<>();
public MutableLiveData<Boolean> getStatusCode(String activationCode) {
status.postValue(Boolean.valueOf(false));
return status;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With