web-dev-qa-db-ja.com

java.lang.IllegalArgumentException:@Urlは@GET URL(パラメーター#1)では使用できません

@GET("user/token/")
Observable<String> gToken(@Url String url, @Query("usertype") int userType);

次のエラーが発生します。

Process: com.gouhuoapp.say, PID: 12519
rx.exceptions.OnErrorNotImplementedException: @Url cannot be used with @GET URL (parameter #1)
    for method ApiService.getToken
    at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.Java:386)
    at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.Java:383)
    at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.Java:44)
    at rx.observers.SafeSubscriber._onError(SafeSubscriber.Java:153)
    at rx.observers.SafeSubscriber.onError(SafeSubscriber.Java:115)
    at rx.exceptions.Exceptions.throwOrReport(Exceptions.Java:216)
    at rx.observers.SafeSubscriber.onNext(SafeSubscriber.Java:139)
    at rx.observers.SerializedObserver.onNext(SerializedObserver.Java:91)
    at rx.observers.SerializedSubscriber.onNext(SerializedSubscriber.Java:94)
    at rx.internal.operators.OperatorTakeUntil$1.onNext(OperatorTakeUntil.Java:45)
    at rx.internal.operators.OperatorThrottleFirst$1.onNext(OperatorThrottleFirst.Java:53)
    at com.jakewharton.rxbinding.view.ViewClickOnSubscribe$1.onClick(ViewClickOnSubscribe.Java:23)
    at Android.view.View.performClick(View.Java:4909)
    at Android.view.View$PerformClick.run(View.Java:20390)
    at Android.os.Handler.handleCallback(Handler.Java:815)
    at Android.os.Handler.dispatchMessage(Handler.Java:104)
    at Android.os.Looper.loop(Looper.Java:192)
    at Android.app.ActivityThread.main(ActivityThread.Java:5784)
    at Java.lang.reflect.Method.invoke(Native Method)
    at Java.lang.reflect.Method.invoke(Method.Java:372)
    at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:1084)
    at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:850)
 Caused by: Java.lang.IllegalArgumentException: @Url cannot be used with @GET URL (parameter #1)
    for method ApiService.getToken
    at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.Java:720)
    at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.Java:711)
    at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.Java:729)
    at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.Java:367)
    at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.Java:333)
    at retrofit2.ServiceMethod$Builder.build(ServiceMethod.Java:202)
    at retrofit2.Retrofit.loadServiceMethod(Retrofit.Java:166)
    at retrofit2.Retrofit$1.invoke(Retrofit.Java:145)
    at Java.lang.reflect.Proxy.invoke(Proxy.Java:397)
    at $Proxy3.getToken(Unknown Source)
    at com.gouhuoapp.say.data.DataManager.getToken(DataManager.Java:83)
    at com.gouhuoapp.say.view.activity.RegisterMobileActivity.getQiniuToken(RegisterMobileActivity.Java:171)
    at com.gouhuoapp.say.view.activity.RegisterMobileActivity.lambda$initTitle$4(RegisterMobileActivity.Java:153)
    at com.gouhuoapp.say.view.activity.RegisterMobileActivity$$Lambda$7.call(Unknown Source)
    at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.Java:39)
    at rx.observers.SafeSubscriber.onNext(SafeSubscriber.Java:134)
        ... 15 more
15
woniu

エラーは正確に言うことを意味します。パラメータでGET(...)または@Urlを使用できますが、両方を同時に使用することはできません。 @Urlを使用する必要がある場合は、@GETアノテーションからURLを削除してください。にあったURLの一部をurlパラメータに追加する必要があります。

@GET
Observable<String> gToken(@Url String url, @Query("usertype") int userType);
29
iagreen