I want to send an array of long numbers to the server, I get this array from the adapter recyclerview and then I want to send this array to the server. But for some reason I get an error:

 java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #2) for method APIService.delete_several_message 

I understand from the error that the problem is in parameter 2, this is how this parameter looks in the interface:

 Call<Delete_several_messages> delete_several_message(@Header("Authorization") String token, HashSet<Integer> k, @Query("type") int type); 

here is the class created for this process:

 public class Delete_several_messages { @SerializedName("ids") @Expose private Set <Integer> [] ids; public Set <Integer> [] getIds() { return ids; } } 

and that's how I call everything in the main class:

 mAPIService.delete_several_message("Bearer " + a_token,checked,2).enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { } @Override public void onFailure(Call call, Throwable t) { } }); 

Here is this part:

 mAPIService.delete_several_message("Bearer " + a_token,checked,2) 

highlighted in yellow, and the message hangs there: unchecked call to .enqueue(CallBack<T>)...

The call occurs in the method that is attached to the button click:

 private void deleteGroup(HashSet checked) 

This is where and how this method is registered when you press the button:

 deleteBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MessageCenter.this, String.valueOf(ListAdapter.getChecked()), Toast.LENGTH_SHORT).show(); deleteGroup(ListAdapter.getChecked()); } }); 

This set comes from the adapter.

I honestly say the first time a similar problem occurs, most often requests are sent normally. What could be the problem, besides the one that sits in front of the computer?)

  • The second parameter is not marked by any annotation and the retrofit does not know what to do with it, where to shove. I suspect that you again lured hi to the answer. What is waiting for you from the server and what should return in response? - woesss
  • the server expects me to send him an array of id letters to json that I need to delete, in response, I’ll just receive a notification that everything is OK, that is, no data will be sent back - Andrew Goroshko
  • That is, Delete_several_messages ? And what are you sending him ... - woesss
  • did not understand the question) do you want to say that my array is incorrectly built? - Andrew Goroshko
  • Complete the question with the request and response formats. If you just have to pass an array, not an array in the object - try marking the second parameter with the annotation @Body - woesss

1 answer 1

The error means that all parameters of the API method for the Retrofit should be marked with annotations indicating the Retrofit what to do with this parameter.

From all clarified, such codes are obtained, try:

 @HTTP(method = "DELETE", path = "your/path", hasBody = true) Call<ResponseBody> delete_several_message(@Header("Authorization") String token, @Body Delete_several_messages k, @Query("type") int type); 

 private void deleteGroup(HashSet checked) { Delete_several_messages body = new Delete_several_messages(checked); mAPIService.delete_several_message("Bearer " + a_token, body, 2) } 

 public class Delete_several_messages { @SerializedName("ids") @Expose private Set<Integer> ids; public Delete_several_messages(Set<Integer> ids) { this.ids = ids; } public Set<Integer> getIds() { return ids; } } 
  • everything seems to work as it should)) but now the array comes up empty) - Andrew Goroshko
  • Comes empty to the server or immediately from the adapter is already empty? - woesss 2:01 pm
  • what goes to the server, I see that it is empty, but I don’t see what comes out of the adapter, but I admit that it’s also empty - Andrew Goroshko
  • I think that the adapter has a problem, because the main class calls the adapter method to get the array - Andrew Goroshko
  • Well, output to the log or via debugger look - it is empty / not empty in this place - woesss