【问题标题】:RxAndroid with Retrofit 2.0带有 Retrofit 2.0 的 RxAndroid
【发布时间】:2015-12-06 23:08:11
【问题描述】:

我有界面

 @GET("/data, 2.5/forecast/daily")
   Observable<MultilingualWeather> getWeatherByIdWithMultilingual(
    @Query("id") String id,
    @Query("lang") String lang,
    @Query("appid") String appid);

MainActivity 在以下配置中被调用

 Retrofit retrofit_weather = new Retrofit.Builder().
        baseUrl(BASE_URL).
        addConverterFactory(GsonConverterFactory.create()).
        addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
        build();

GetWeatherForLocation getWeather = retrofit_weather.create(GetWeatherForLocation.class);

Observable<MultilingualWeather> call_observable = getWeather.
            getWeatherByIdWithMultilingual(
            CITY_ID,
            LANG,
            KEY
    );

    subscription = call_observable.subscribe(subscriber);

以下文件依赖

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'

}

毕竟这会引发异常

 FATAL EXCEPTION: main Process: com.example.alex.weatherclient, PID: 16658 java.lang.AbstractMethodError: abstract method "retrofit.CallAdapter retrofit.CallAdapter$Factory.get(java.lang.reflect.Type, java.lang.annotation.Annotation[], retrofit.Retrofit)"         

【问题讨论】:

  • 您有没有不小心为您的任何改造依赖项使用了不同的版本? Possibly related Q&A.
  • 是的,有同样的问题,我会尝试更改为 beta2,看看是否能解决问题。

标签: android retrofit rx-android


【解决方案1】:

在 build.gradle 中替换

compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1' 

compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'

【讨论】:

    【解决方案2】:

    看起来像是一个错字。你的界面使用getWeatherByIdWithMultilingual,你的代码使用getWeatherByIdWithMultilingual2

    【讨论】:

      猜你喜欢
      • 2019-04-04
      • 2020-01-02
      • 1970-01-01
      • 2020-08-14
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      相关资源
      最近更新 更多