尝试通过改装从 OMDb API 获取 post 但错误提示 URL 查询字符串不能包含替换块

Trying to get post from the OMDb API by retrofit but error says URL query string must not have replace block

我正在尝试通过 OMDb API 获取电影情节或发行年份。当我键入电影名称时,我收到此错误消息:

URL query string must not have replace block

我改的是界面中的调用方式,而不是查询的路径:

@GET("?t={id}&apikey=apikey(that's private)")
Call<Post> getPost(@Query("id") String name);

但是我得到了同样的错误信息。

这是我的代码。

主要活动

public class MainActivity extends AppCompatActivity {

TextView tvText;

Retrofit retrofit;
ApiInterface apiInterface;
Call<Post> call;

EditText editText;
Button getButton;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvText=findViewById(R.id.tvText);
editText=findViewById(R.id.editText);
getButton=findViewById(R.id.getButton);


} 

public void get(View view) {

retrofit = new Retrofit.Builder()
        .baseUrl("http://www.omdbapi.com/")
        .addConverterFactory(GsonConverterFactory.create())
        .build();

apiInterface = retrofit.create(ApiInterface.class);

call = apiInterface.getPost(editText.getText().toString());

call.enqueue(new Callback<Post>() {
    @Override
    public void onResponse(Call<Post> call, Response<Post> response) {
        tvText.setText(response.body().getPlot());

    }

    @Override
    public void onFailure(Call<Post> call, Throwable t) {
        Toast.makeText(MainActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
    }

});
}
 }

接口:

public interface ApiInterface {

@GET("?t={id}&apikey=apikey(that's private)")
Call<Post> getPost(@Path("id") String name);
}

Post class 对于 JSON 键:

public class Post {

private int Year;
private String Plot;
private String Title;


public int getYear() {
return Year;
}

public String getPlot() {
return Plot;
}

public String getTitle() {
return Title;
}
}

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res        /android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvText"
android:layout_width="324dp"
android:layout_height="92dp"
android:layout_marginTop="72dp"
android:layout_marginRight="4dp"
app:layout_constraintHorizontal_bias="0.535"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="88dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/getButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="7dp"
android:clickable="true"
android:onClick="get"
android:text="get"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvText" />

</android.support.constraint.ConstraintLayout>

从注释中删除 t={id} 并直接在 @Query 中使用查询参数名称,如下所示:

@GET("?apikey=apikey(that's private)")
Call<Post> getPost(@Query("t") String id);