首页 > 解决方案 > 获取模型尚未初始化。请先 buildModel 进行改造 api 调用

问题描述

我正在以这种方式进行改造电话:-

 
           
                APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);
                
                AppLogger.getInstance().e("TAG", "Request visit: " +obj1);
                Call<ResponseBody> call1=apimethod(obj1);
                call1.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        AppLogger.getInstance().e("TAG", "Response add " + response.body()
 }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        AppLogger.getInstance().e("Tag", "Response add " +t);
                    }
                });

我的 API 调用就像:-

@POST("route for the route")
    Call<ResponseBody> apimethod(@Body Class1 obj);

我正在以这种方式初始化改造对象:-

public static Retrofit getClient() {
        HttpsTrustManager.allowAllSSL();
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
        client=getUnsafeOkHttpClient().build();

        retrofit = new Retrofit.Builder()
                .baseUrl("<apiurl>")
                .addConverterFactory(GsonConverterFactory.create())
                .client(getUnsafeOkHttpClient().build())
                .build();



        return retrofit;
    }

但是在提交响应时:- 根据 api 正文,请求正文是正确的

{Object }

最后的反应就像这很奇怪:-

I/okhttp.OkHttpClient: {"timestamp":"2020-06-28T12:28:20.410+0000","status":404,"error":"Not Found","message":"Model has not been initialized. Please buildModel first","path":"<route for it>"}

这里所有细节都被初始化但无法理解为什么这说模型没有初始化

标签: javaandroidapiandroid-studioretrofit2

解决方案


推荐阅读