ВСЁ ТОЧНО, НО ПОКАЗАТЬ ПОЛИЛИНУ, ПОЛУЧАЮЩУЮ ОШИБКУ С ВЫЗВАННЫМ ИНТЕРФЕЙСОМ - PullRequest
0 голосов
/ 24 апреля 2020

я думаю, что здесь я совершаю некоторую ошибку

Retrofit

import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

public class RetrofitClient {
    private static Retrofit retrofit =null;

    public static Retrofit getClient(String baseURL){
        if (retrofit == null){
            retrofit= new Retrofit.Builder().baseUrl(baseURL).addConverterFactory(ScalarsConverterFactory.create()).build();
        }return retrofit;
    }
}

для URL-адреса Retrofit

public class Common {
    public static final String baseUrl ="https://maps.googleapis.com";
    public static IGoogleApi getGoogleAPI(){
        return RetrofitClient.getClient(baseUrl).create(IGoogleApi.class);
    }
}

для вызова дооснащения

package com.google.rishicab.Romote;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Url;

public interface IGoogleApi {
    @GET
    Call<String> getPath(@Url String url);
}

Я думаю, что-то не так, что я делаю с модернизацией, но не могу найти ошибку.

logcat

createProgram 0x0000000800000000, binary 0x70f41ba6a3, length 10736, format 37168 within 518ns 
D/Gobinda: karnojora 
D/GOBINDA: https://maps.googleapis.com/maps/api/directions/json?mode=driving&transit_routing_preference=less_driving&origin=25.630044,88.1317314&destination=karnojora&key=AIzaSyDa-hkY6VKPVyhqpr********mw 
W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'retrofit2.Call com.google.rishicab.Romote.IGoogleApi.getPath(java.lang.String)' on a null object reference 
W/System.err:     at com.google.rishicab.MapsActivity.getDirection(MapsActivity.java:225)

1 Ответ

0 голосов
/ 05 мая 2020

в моем случае я работаю без общего класса

public class RetrofitClient {
    private static Retrofit retrofit =null;
public static Retrofit getClient() {
        if(null == retrofit) {
            String baseURL = "https://maps.googleapis.com/";
            retrofit = new Retrofit.Builder()
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .client(getOkHttpClient())
                    .baseUrl(baseURL)
                    .build();
        }
        //return retrofit object
        return retrofit;
    }
}

init после onCreate

mServices= RetrofitClient.getClient().create(IGoogleApi.class);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...