RxAndroid与Retrofit 2.0

时间:2015-12-03 20:04:45

标签: android retrofit rx-android

我有界面

 @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)"         

2 个答案:

答案 0 :(得分:5)

替换build.gradle

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

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

答案 1 :(得分:0)

看起来像一个错字。您的界面使用string = ['1', '2', '3', '4', '5', '5', '4', '3', '2', '1'] counter = len(string) holder = '' final = [] while counter > 0: for i in string: if len(holder) >= 5: final.append(holder) holder = '' counter -= 1 else: holder += i counter -= 1 ,您的代码使用getWeatherByIdWithMultilingual