Search code examples
javaandroid-studioretrofit2

My Retrofit Java class keeps returning an error line


I am trying to use an API Call to post a data using Retrofit in my Android app. But my UserService Class keeps pointing me to an error in my line of code. I have checked and checked again and can't seem to get the problem.

package com.example.xxxxx;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;

public class UserService {

    @POST("api/enroll_vehicle")
    Call<UserResponse> saveUser(@Body UserRequest userRequest);

}

Solution

  • Retrofit works with interfaces, not classes. Change the class to interface.

    In addition, if you had a class, the methods there should have a method body. This is likely the error you're seeing.