我遇到了一个错误,没有找到 Retrofit 注释。 (参数#1)。我正在尝试通过谷歌搜索但什么也没有:
fragment 注释.java
private void createNew() {
subscriptions.add(leaderSubscription);
commentDTO.setType(Constants.TRAINING_DAY_OLD);
Observable<ResultResponse> observable = candidateRequest.postResultCandidate(commentDTO);
leaderSubscription = observable.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new JvSubscriber<ResultResponse>(activity) {
@Override
public void handleSuccess(ResultResponse baseResponse) {
if (Constants.SUCCESS.equals(baseResponse.getSuccess())) {
Intent intent = new Intent(getActivity(), TrainingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(intent);
setEnableConfirm();
Toast.makeText(getActivity(), getString(R.string.success), Toast.LENGTH_SHORT).show();
} else {
btnConfirm.setText(R.string.title_enable);
btnConfirm.setBackgroundResource(R.drawable.custom_button_history);
btnConfirm.setEnabled(true);
Toast.makeText(getActivity(),baseResponse.getMessage(), Toast.LENGTH_SHORT).show();
}
Log.d(TAG, "JV-SUCCESS: ");
}
});
subscriptions.add(leaderSubscription);
CandidateRequest.java
public interface CandidateRequest {
@Headers("Content-Type: application/json")
@POST(Constants.URL_RESULT_CANDIDATE)
Observable<ResultResponse> postResultCandidate(
@Body CommentDTO commentDTO);
@GET(Constants.URL_STAFF_SCHEDULE_LIST)
Observable<StaffResponse> getSchedulesByStaffId(
@Path("id") long maidId,
@Path("fromDate") long fromDate,
@Path("toDate") long toDate);
@GET(Constants.URL_LEADER_NAME)
Observable<CandidateLeaderResponse> getLeaderName();
}
文件 build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.0.2'
compile 'com.android.support:support-v13:23.0.0'
compile 'com.android.support:design:23.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.4.+'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.+'
compile 'com.squareup:otto:1.3.5'
compile 'com.onesignal:OneSignal:3.+@aar'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
ext.googlePlayVersion = "9.6.1"
compile "com.google.firebase:firebase-ads:$googlePlayVersion"
compile "com.google.firebase:firebase-database:$googlePlayVersion"
compile "com.google.android.gms:play-services-ads:$googlePlayVersion"
compile "com.google.android.gms:play-services-maps:$googlePlayVersion"
compile "com.google.android.gms:play-services-gcm:$googlePlayVersion"
compile "com.google.android.gms:play-services-analytics:$googlePlayVersion"
compile "com.google.android.gms:play-services-location:$googlePlayVersion"
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
}
最佳答案
问题
您将 Retrofit 1 注释与 Retrofit 2 一起使用,反之亦然。版本 1 和 2 可以并排使用。这并不意味着它们的注释与其他版本兼容。
原因
你的 dependencies
block 一团糟。
解决方案
移除 Retrofit 1。仅在您自己的新代码中使用 Retrofit 2。修复导入语句,从 retrofit2.*
包中导入 Retrofit 注释。
更多建议
删除 OkHttp 2 并显式添加 OkHttp 3(Retrofit 2 已经隐式添加了 OkHttp 3.0,这还不够好)。仅在您自己的新代码中使用 OkHttp 3。
不要使用不同版本的不同支持库。使用与 Google Play 服务相同的方法。将版本字符串提取到变量并使用它。您还两次指定了 appcompat-v7。如果您不遵循此特定建议,您最终将遇到运行时错误。
关于android - java.lang.IllegalArgumentException : No Retrofit annotation found.(参数#1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275776/