Я не могу отправить запрос API, используя модификацию android или получить ответ от APi - PullRequest
0 голосов
/ 11 февраля 2020

Сначала я столкнулся с этой ошибкой java.lang.BootstrapMethodError: Exception from call site #4

Затем я решил ее, добавив

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
} 

Я решил эту ошибку, но, к сожалению, не могу отправить запрос API или получить какой-либо ответ в моем приложении android. Может кто-нибудь сказать мне, что мне не хватает?

Вот фрагмент кода, который отправляет запрос

@Override
public void onClick(View v) {

    //checking for the shared preferences and saving button instance
    if ( cardView.isEnabled () ) {


    Toast.makeText (getActivity (), "Request Sent to SNAL", Toast.LENGTH_LONG).show ();

    //fetching data from the api
    Retrofit retrofit = new Retrofit.Builder ()
                        .baseUrl ("https://api.myjson.com/")
                        .addConverterFactory (GsonConverterFactory.create ())
                        .build ();

    OcappJsonApiSNAL ocappJsonApi = retrofit.create (OcappJsonApiSNAL.class);

    Call<List<StudentClearanceSNAL>> listCall = ocappJsonApi.getStudents ();

    listCall.enqueue (new Callback<List<StudentClearanceSNAL>> () {
        @Override
        public void onResponse(Call<List<StudentClearanceSNAL>> call, Response<List<StudentClearanceSNAL>> response) {

            if(!response.isSuccessful ()){
                Toast.makeText (getActivity (),"From OCApp " + response.code (),Toast.LENGTH_LONG).show ();
                return;
            }

            List<StudentClearanceSNAL> studentClearancess = response.body ();
    }
}
...