Reputation: 155
I'm following a tutorial online to get information from a local API using retrofit2, but when I run my code I get:
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
I notice most answers online have this problem when POSTing but all I'm trying to do is GET all the items in the database. The API part o this works and when I go to the local IP (10.0.2.2) on the emulator it gives me what I want. I don't understand why I'm getting this problem, actually still trying to fully understand the base code. I also saw some solutions using .enqueue but I guess i don't fully understand how to use it.
@GET("/institute/Students")
void getStudent(Callback<List<Student>> callback);
InstituteService serv = restService.getService();
serv.getStudent(new Callback<List<Student>>() {...}
I'm trying to get a list of students from my database but I'm stuck right here. After initiating the Callback it goes straight to the onFailure activity. Any point in the right direction appreciated.
Upvotes: 2
Views: 382
Reputation: 2504
Noticed that you are using callback
not call
and that too I guess goes as return type not as a parameter.
This interface will return list of students, you can pass query parameters to function if required (eg. StudentId)
@GET("institutes/students/")
Call<List<Student>> getStudentsData();
Please see this article for more information
Upvotes: 1
Reputation: 76859
These interface descriptions should return Call
instead of void
:
import retrofit2.Call;
import retrofit2.http.GET;
...
@GET("institute/students")
Call<ArrayList<Student>> getStudents();
Upvotes: 2