Android LiveData转换和失败的绑定交易

时间:2019-01-04 20:39:38

标签: android android-livedata

我正在尝试第一次使用SwitchMap转换,但是我不知道可以解决一些错误。我想将数据从存储库中获取到视图模型,但仍然存在该错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.daniellachacz.currencyconverter2, PID: 25451
java.lang.StackOverflowError: stack size 8MB
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    at com.example.daniellachacz.currencyconverter2.data.CurrencyRepository.getRate(CurrencyRepository.java:75)
    a

我在viewmodel中的代码:

 private final MutableLiveData<String> mRate = new MutableLiveData<>();
public final LiveData<String> rateValue =
        Transformations.switchMap(mRate, (rate) -> currencyRepository.getRate(rate));

 private void getThing(String rate) {
    rateValue.getValue();
    Log.d(TAG, rate);
}

0 个答案:

没有答案