gpt4 book ai didi

android - 带有 Retrofit 2.0 的 RxAndroid

转载 作者:行者123 更新时间:2023-11-29 15:08:52 25 4
gpt4 key购买 nike

我有接口(interface)

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

最佳答案

在build.gradle中替换

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

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

关于android - 带有 Retrofit 2.0 的 RxAndroid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34075155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com