我有一个类需要通过发送激活码激活应用程序。但我总是遇到这个错误。 “无法为io.reactivex.Observable创建调用适配器” 我跟踪了这个链接上的所有家属。 Unable to create call adapter for io.reactivex.Observable但错误仍然相同。请帮忙。 顺便说一句,这是我的代码
Activate.java
private void activateApp(String activationCode) {
ServiceGenerator.changeApiBaseUrl(BASE_URL);
apiHandler = ServiceGenerator.createService(HandlerAPI.class);
Observable<AuthenticateModel> observable = a
apiHandler.authApp(activationCode)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
Observer<AuthenticateModel> observer = new Observer<AuthenticateModel>() {
@Override
public void onSubscribe(Disposable d) {
Log.d("AUTHENTICATE", d.toString());
}
@Override
public void onNext(AuthenticateModel authenticateModel) {
Log.d("AUTHENTICATE", authenticateModel.getAssignedTo());
Log.d("AUTHENTICATE", authenticateModel.getIsActive());
Log.d("AUTHENTICATE", authenticateModel.getUnlockerCode());
Log.d("AUTHENTICATE",
Integer.toString(authenticateModel.getAuthenticateId()));
}
@Override
public void onError(Throwable e) {
Log.d("AUTHENTICATE", e.getMessage().toString());
}
@Override
public void onComplete() {
Log.d("AUTHENTICATE", "FINISH");
}
};
observable.subscribe(observer);
}
APIHandler
public interface HandlerAPI {
@GET("/authenticateapp/getcode")
Observable<AuthenticateModel> authApp(@Query("code") String activationCode);
}
AuthenticateModel.java
public class AuthenticateModel {
private int authenticateId;
private String assignedTo;
private int idRDM;
private String isActive;
private String unlockerCode;
public AuthenticateModel() {
}
public AuthenticateModel(int authenticateId, String assignedTo, int idRDM,
String isActive, String unlockerCode) {
this.authenticateId = authenticateId;
this.assignedTo = assignedTo;
this.idRDM = idRDM;
this.isActive = isActive;
this.unlockerCode = unlockerCode;
}
public int getAuthenticateId() {
return authenticateId;
}
public void setAuthenticateId(int authenticateId) {
this.authenticateId = authenticateId;
}
public String getAssignedTo() {
return assignedTo;
}
public void setAssignedTo(String assignedTo) {
this.assignedTo = assignedTo;
}
public int getIdRDM() {
return idRDM;
}
public void setIdRDM(int idRDM) {
this.idRDM = idRDM;
}
public String getIsActive() {
return isActive;
}
public void setIsActive(String isActive) {
this.isActive = isActive;
}
public String getUnlockerCode() {
return unlockerCode;
}
public void setUnlockerCode(String unlockerCode) {
this.unlockerCode = unlockerCode;
}
}
ServiceGenerator.java
private static Retrofit.Builder builder =
new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
// <- add this
.baseUrl(apiBaseUrl)
.client(getRequestHeader());
public static <S> S createService(
Class<S> serviceClass) {
httpClient.addInterceptor(logging);
builder.client(httpClient.build());
retrofit = builder.build();
return retrofit.create(serviceClass);
}
的build.gradle
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.5'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'