我已将BaseCallBack类创建为通用类以进行改装,但会引发该错误:
无法创建呼叫适配器
这是<script src='https://unpkg.com/@ionic/core@0.0.2-20/dist/ionic.js'></script>
BaseCallback.class
}
这是public class BaseCallBack<T extends ResponseObject> implements Callback<BaseResponse<T>> {
public static final String TAG = BaseCallBack.class.getSimpleName();
@Override
public void onResponse(Call<BaseResponse<T>> call, Response<BaseResponse<T>> response) {
if (checkInternet(response) && response.isSuccessful()) {
verifyResponse(response.body());
complete();
} else if (!response.isSuccessful() && response.code() == 401) {
EventBus.getDefault().post(new UnAuthErrorEvent());
}
}
@Override
public void onFailure(Call<BaseResponse<T>> call, Throwable t) {
if (t instanceof SocketTimeoutException) {
EventBus.getDefault().post(new NoInternetEvent());
} else {
handleFail(t.getMessage());
}
complete();
}
protected boolean checkInternet(Response<BaseResponse<T>> response) {
if (response.code() == DataHolder.NO_INTERNET) {
EventBus.getDefault().post(new NoInternetEvent());
complete();
return false;
}
return true;
}
protected void verifyResponse(BaseResponse<T> response) {
if (response == null)
handleFail((String) null);
else
handleSuccess(response.getData());
}
protected void handleSuccess(T response) {
if (response != null)
EventBus.getDefault().post(response);
}
protected void handleFail(BaseResponse response) {
EventBus.getDefault().post(new FailEvent("failed"));
if (response.getErrors() == 401) {
EventBus.getDefault().post(new UnAuthErrorEvent());
}
}
protected void handleFail(String message) {
EventBus.getDefault().post(new FailEvent(message));
}
protected void complete() {
EventBus.getDefault().post(new CompleteEvent());
}
:
ResponseObject.class
这是服务的界面
public class ResponseObject extends BaseObservable {
}
这就是我的称呼
@GET(ServicesHolder.specialities)
BaseCallBack<BaseResponse<DataObject<SpecialitiesDM>>> getSpecialities();
我在尝试调用服务时使用Dagger注入RETROFIT和ServiceInterface只是抛出了直到现在我都无法处理的错误,我看到了很多答案,但它与RxJava有关而且我没有在应用程序中使用RxJava