java.lang.IllegalArgumentException : 不能有替换块。对于动态查询参数,使用@Query

java.lang.IllegalArgumentException : must not have replace block. For dynamic query parameters use @Query

我正在尝试使用 API 和 'convert' 端点将 USD 转换为 INR b,这是我一次又一次面临的错误

java.lang.IllegalArgumentException: URL query string "api_key={api_key}&base={base}&to={to}&amount={amount}" must not have replace block. For dynamic query parameters use @Query.
    for method RetrofitClient.getConvertedValue
    at retrofit2.Utils.methodError(Utils.java:52)
    at retrofit2.Utils.methodError(Utils.java:42)
    at retrofit2.RequestFactory$Builder.parseHttpMethodAndPath(RequestFactory.java:257)
    at retrofit2.RequestFactory$Builder.parseMethodAnnotation(RequestFactory.java:205)
    at retrofit2.RequestFactory$Builder.build(RequestFactory.java:161)
    at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:65)
    at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:25)
    at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:168)
    at retrofit2.Retrofit.invoke(Retrofit.java:147)
    at java.lang.reflect.Proxy.invoke(Proxy.java:813)
    at $Proxy0.getConvertedValue(Unknown Source)
    at com.example.online_currency.MainActivity.onClick(MainActivity.java:57)
    at android.view.View.performClick(View.java:5609)
    at android.view.View$PerformClick.run(View.java:22263)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

//这是我的 class 我正在创建改造对象的地方

public class MainActivity 扩展 AppCompatActivity 实现 View.OnClickListener{

private static final String TAG = "MainActivity";
private TextView result;
private EditText currency;
private Button button;
private static String BASE_URL = "https://api.currencyscoop.com/v1/";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d(TAG, "onCreate: called");
    initViews();
    button.setOnClickListener(this);
}

public void initViews(){
    Log.d(TAG, "initViews: called");
    result = findViewById(R.id.result);
    currency = findViewById(R.id.amount);
    button = findViewById(R.id.button);
}

@Override
public void onClick(View v) {
    Log.d(TAG, "onClick: called");
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    RetrofitClient retrofitClient = retrofit.create(RetrofitClient.class);
    Call<ConvertAmt> calling = retrofitClient.getConvertedValue("<my_api_key>","USD", "INR", currency.getText().toString());
    calling.enqueue(new Callback<ConvertAmt>() {
        @Override
        public void onResponse(Call<ConvertAmt> call, Response<ConvertAmt> response) {
            Log.d(TAG, "onResponse: called :----------------------> "+response.body().getResult());
        }

        @Override
        public void onFailure(Call<ConvertAmt> call, Throwable t) {
            Toast.makeText(MainActivity.this, "Error "+t.getMessage(),Toast.LENGTH_LONG).show();
        }
    });
}

}

//here is my RetrofitClient interface

public 接口 RetrofitClient {

@GET("convert?api_key={api_key}&base={base}&to={to}&amount={amount}")
Call<ConvertAmt> getConvertedValue(@Query("api_key") String api_key, @Query("base") String base, @Query("to") String to, @Query("amount") String amount);

}

请试试这个,提到的端点不正确。

@GET("/convert")
Call<ConvertAmt> getConvertedValue(@Query("api_key") String api_key, @Query("base") String base, @Query("to") String to, @Query("amount") String amount);