我正在按照在线教程使用 Retrofit2 从本地 API 获取信息,但是当我运行代码时,我得到:
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
我注意到大多数在线答案在发布时都有这个问题,但我想做的就是获取数据库中的所有项目。 API 部分可以正常工作,当我在模拟器上访问本地 IP (10.0.2.2) 时,它会提供我想要的内容。我不明白为什么我会遇到这个问题,实际上仍在尝试完全理解基本代码。我还看到了一些使用 .enqueue 的解决方案,但我想我并不完全理解如何使用它。
@GET("/institute/Students")
void getStudent(Callback<List<Student>> callback);
InstituteService serv = restService.getService();
serv.getStudent(new Callback<List<Student>>() {...}
我正在尝试从数据库中获取学生列表,但我被困在这里。启动回调后,它会直接进入 onFailure Activity 。任何方向正确的观点都会受到赞赏。
最佳答案
这些接口(interface)描述应返回Call
而不是void
:
import retrofit2.Call;
import retrofit2.http.GET;
...
@GET("institute/students")
Call<ArrayList<Student>> getStudents();
关于java - 如何修复简单 GET 回调中的 "No Retrofit annotation found."?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57827225/