Hi I'm new to Retrfoit 2. I want to fetch data using Retrofit 2.My API retrieves data in JSON Format. I'm sending parameter to API through the app. API is working fine when I tested it in browser. I'm getting on a null object reference but I have checked all things.
This is what I tried.
Model class
public class Detail {
@SerializedName("PromoId")
@Expose
private String PromoId;
@SerializedName("PromoName")
@Expose
private String PromoName;
@SerializedName("Category")
@Expose
private String Category;
@SerializedName("PromoImg")
@Expose
private String PromoImg;
@SerializedName("compName")
@Expose
private String compName;
public String getCompName() {
    return compName;
}
public void setCompName(String compName) {
    this.compName = compName;
}
public String getPromoId() {
    return PromoId;
}
public void setPromoId(String promoId) {
    PromoId = promoId;
}
public String getPromoName() {
    return PromoName;
}
public void setPromoName(String promoName) {
    PromoName = promoName;
}
public String getCategory() {
    return Category;
}
public void setCategory(String category) {
    Category = category;
}
public String getPromoImg() {
    return PromoImg;
}
public void setPromoImg(String promoImg) {
    PromoImg = promoImg;
}}
Api Client
public class ApiClient {
public static final String BASE_URL = "http://example.com";
public static Retrofit retrofit = null;
public static Retrofit getApiClient (){
    if(retrofit==null){
        retrofit = new Retrofit.Builder().baseUrl(BASE_URL).
                addConverterFactory(GsonConverterFactory.create()).build();
    }
    return retrofit;
}}
Api Interface
public interface ApiInterface {
    @POST("/api/customer/{PromoId}")
    Call<Detail> getReponse(@Path("PromoId") String PromoId) ;
}
Main Activity
public class MainActivity extends Activity {
private ApiInterface apiInterface;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv = (TextView)findViewById(R.id.textView);
    getDataForId("3");
}
public void getDataForId(final String id){
    apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
    Call<Detail> call = apiInterface.getReponse(id);
    call.enqueue(new Callback<Detail>() {
        @Override
        public void onResponse(Call<Detail> call, Response<Detail> response) {
            final Detail myResponse = response.body();
            Toast.makeText(getApplicationContext(), "Inside on Response", Toast.LENGTH_SHORT).show();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    tv=(TextView)findViewById(R.id.textView);
                    tv.setText(myResponse.getCategory());
                }
            });
        }
        @Override
        public void onFailure(Call<Detail> call, Throwable t) {
            Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_SHORT).show();
        }
    });}}
 
    