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

安吉帕里克

我正在尝试使用具有'convert'终结点的API将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$1.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)

//这里是我正在创建改造对象的班级

公共类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

公共接口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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

java.lang.IllegalArgumentException:URL查询字符串对于动态查询参数,请使用@Query。用于方法OpenWeatherApi.currentWeatherDetails

java.lang.IllegalArgumentException:不能具有viewTypeCount <1

面对 java.lang.IllegalArgumentException

java.lang.IllegalArgumentException onActivityResult

错误:java.lang.IllegalArgumentException

java.lang.IllegalArgumentException异常:@url不能与@GET URL被使用(参数#1)

java.lang.IllegalArgumentException:对于Kotlin和WebView,指定为非null的参数为null

java.lang.IllegalArgumentException:SQL 数组不能为空

OrientDB:java.lang.IllegalArgumentException 属性值不能为空

java.lang.IllegalArgumentException:方法不能为null

java.lang.IllegalArgumentException:迭代变量不能为null

java.lang.IllegalArgumentException:主机名不能为null

QuickSort 方法中的 java.lang.IllegalArgumentException

JPA:java.lang.IllegalArgumentException:不是实体

VolleyError:java.lang.IllegalArgumentException:超时<0

java.lang.IllegalArgumentException:无效的列名

java.lang.IllegalArgumentException:空键

java.lang.IllegalArgumentException:provider =网络

奇怪的java.lang.IllegalArgumentException异常

java.lang.IllegalArgumentException:未知实体

XQuery Saxon异常(java.lang.IllegalArgumentException)

获取错误java.lang.IllegalArgumentException

unregisterReceiver原因:java.lang.IllegalArgumentException

java.lang.IllegalArgumentException:nativePtr 为空

java.lang.illegalArgumentException意外显示

改造错误 - java.lang.IllegalArgumentException

java.lang.IllegalArgumentException:无法创建组件

java.lang.IllegalArgumentException:发布管理

比较器错误 java.lang.IllegalArgumentException