gpt4 book ai didi

java.lang.IllegalArgumentException : FormUrlEncoded can only be specified on HTTP methods with request body (e. g., @POST)

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:11:22 28 4
gpt4 key购买 nike

我正在尝试通过 API 上的 GET 方法从数据库中获取数据

这是我的代码

APIServive.Interface

public interface APIService {
@FormUrlEncoded
@GET("Event")
Call<ApiResponseModel> viewEvent();
}

EventModel.Java

 public class EventModel {

@SerializedName("nama_event") String nama_event;
@SerializedName("jenis_event") String jenis_event;
@SerializedName("creator") String creator;
@SerializedName("deskripsi_event") String deskripsi_event;
@SerializedName("tanggal") String tanggal;
@SerializedName("status") String status;

public String getNama_event() {
return nama_event;
}

public String getJenis_event() {
return jenis_event;
}

public String getCreator() {
return creator;
}

public String getDesk_event() {
return deskripsi_event;
}

public String getTanggal_event() {
return tanggal;
}

public String getStatus() {
return status;
}
}

ViewActivity.Java

 public class ViewEventActivity extends AppCompatActivity {
@OnClick(R.id.back_arrow)void balik(){
finish();
}
@BindView(R.id.search_acara)EditText searchEvent;
public static final String URL = "http://iseoo.id/rest_ci_iseoo/";
private List<EventModel> acara = new ArrayList<>();
RecyclerView.LayoutManager mlayoutManager;
private RecyclerViewAdapter viewAdapter;
@BindView(R.id.recyclerViewEvent)RecyclerView recyclerView;
@BindView(R.id.progress_bar)ProgressBar progressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_event);
ButterKnife.bind(this);

viewAdapter = new RecyclerViewAdapter(ViewEventActivity.this, acara);
mlayoutManager = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(mlayoutManager);
recyclerView.setAdapter(viewAdapter);
Retrofit retrofit=new
Retrofit.Builder().baseUrl(URL).
addConverterFactory(GsonConverterFactory.create()).build();
APIService API = retrofit.create(APIService.class);
Call<ApiResponseModel> getData = API.viewEvent();
getData.enqueue(new Callback<ApiResponseModel>() {
@Override
public void onResponse(Call<ApiResponseModel> call,
Response<ApiResponseModel> response) {
progressBar.setVisibility(View.GONE);
acara = response.body().getResult();
viewAdapter = new
RecyclerViewAdapter(ViewEventActivity.this, acara);
recyclerView.setAdapter(viewAdapter);
viewAdapter.notifyDataSetChanged();
}
// }

@Override
public void onFailure(Call<ApiResponseModel> call, Throwable t) {

}
});}}

当我运行应用程序时,它给出了这个

Caused by: java.lang.IllegalArgumentException: FormUrlEncoded can only be 
specified on HTTP methods with request body (e.g., @POST).
for method APIService.viewEvent
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:752)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:743)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:185)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy0.viewEvent(Unknown Source)
at
com.example.lenovog480.iseooalpha.ViewEventActivity.onCreate
(ViewEventActivity.java:61)
at android.app.Activity.performCreate(Activity.java:6127)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2630)

我已经搜索过这个问题并试图解决它,但直到现在我还没有找到这个问题的正确答案,如果可能的话你可以联系我因为我真的需要帮助

请任何人帮助我并挽救我的生命谢谢:')

最佳答案

If you add @FromUrlEncoded to the top of @GET, you will have java.lang.IllegalArgumentException: FormUrlEncoded can only be
specified on HTTP methods with request body (e.g., @POST).

删除代码中的@FormUrlEncoded

public interface APIService {

@GET("Event")
Call<ApiResponseModel> viewEvent();
}

关于java.lang.IllegalArgumentException : FormUrlEncoded can only be specified on HTTP methods with request body (e. g., @POST),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46965938/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com