java.lang.IllegalArgumentException:@Url不能与@GET URL 一起使用(参数 #1)

2022-09-01 15:14:25
@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

答案 1

错误的含义与它所说的完全相同,您可以在参数上使用或,但不能同时使用两者。如果需要使用 ,请从注释中删除 url。您需要将 url 参数中包含的 url 部分添加到 url 参数中。GET(...)@Url@Url@GET

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

答案 2