Java 获得404响应和应用程序崩溃改造

Java 获得404响应和应用程序崩溃改造,java,android,retrofit2,Java,Android,Retrofit2,我正在尝试在我的android应用程序中实现与获取和存储广告相关的int值的改造。我从API得到了类似于{“banner\u on”:“1”,“int\u on”:“1”,“int\u click”:“3”}的响应 我在闪屏中使用的代码如下 Retrofit retrofit = ApiClient.getClient(); ApiService apiService = retrofit.create(ApiService.class); api

我正在尝试在我的android应用程序中实现与获取和存储广告相关的int值的改造。我从API得到了类似于
{“banner\u on”:“1”,“int\u on”:“1”,“int\u click”:“3”}
的响应

我在闪屏中使用的代码如下

Retrofit retrofit = ApiClient.getClient();
            ApiService apiService = retrofit.create(ApiService.class);
            apiService.getads().enqueue(new Callback<Ads>() {
                @Override
                public void onResponse(Call<Ads> call, Response<Ads> response) {

                        constant.banner_on = response.body().banner_on();
                        constant.int_on = response.body().int_on();
                        constant.int_click = response.body().int_click();

                }

                 @Override
                 public void onFailure(Call<Ads> call, Throwable t) {

                 }
            });
我的服务如下

public final class Ads {
    @SerializedName("success")

    private int banner_on;
    private int int_on;
    private int int_click;

    public int banner_on() {
        return banner_on;
    }
    public int int_on() {
        return int_on;
    }
    public int int_click() {
        return int_click;
    }
}
 @GET("getads.php")
    Call<Ads>getads();
java.lang.NullPointerException: Attempt to invoke virtual method 'int com.myapp.example.model.Ads.banner_on()' on a null object reference
如果有人能纠正我的错误,请告诉我。 谢谢

如果请求失败,response.body()将为空

if(response.isSuccessful()) //use response.body();
else // use response.errorBody();
如果请求失败,response.body()将为null

if(response.isSuccessful()) //use response.body();
else // use response.errorBody();

@Priya这应该是一个打字错误,使用isSuccessful@Priya这应该是一个输入错误,请使用isSuccessful