简体   繁体   English

Retrofit 2.7.1 无法调用api请求

[英]Retrofit 2.7.1 can't call api request

I have implemented the Api calls using Refrofit 2.7.1 on android but unfortunately i dont get any response on my app if the response was to be returned then it return a notification that returns a json.我已经在 android 上使用 Refrofit 2.7.1 实现了 Api 调用,但不幸的是,如果要返回响应,我的应用程序没有得到任何响应,然后它返回一个返回 json 的通知。 at first it was working properly but after i got the ava.lang.BootstrapMethodError: it didn't response again even after i resolved it but i still don't get any response on my api calls.起初它工作正常,但在我得到 ava.lang.BootstrapMethodError 之后:即使我解决了它,它也没有再次响应,但我的 api 调用仍然没有得到任何响应。

here is my retrofit dependency这是我的改造依赖

implementation 'com.squareup.retrofit2:retrofit:2.7.1'
 implementation 'com.squareup.retrofit2:converter-gson:2.7.1'

here is my api call这是我的 api 调用

button4.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick(View v) {

                Toast.makeText (getActivity (),"Request Sent ",Toast.LENGTH_SHORT).show ();
                //fetching data from the api
                Retrofit retrofit = new Retrofit.Builder ()
                        .baseUrl ("https://api.myjson.com/")
                        .addConverterFactory (GsonConverterFactory.create ())
                        .build ();


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

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


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

                        if(!response.isSuccessful ())
                        {

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

                        List<StudentClearanceControlNumber> studentClearancess = response.body ();



                        for (  final StudentClearanceControlNumber studentClearance: studentClearancess)
                        {
                            //firebase checking for registationnumber
                            String user_id = firebaseAuth.getCurrentUser ().getUid ();
                            firebaseAuth.getInstance ().getCurrentUser ();
                            firebaseDatabase = FirebaseDatabase.getInstance ();
                            DatabaseReference databaseReference = firebaseDatabase.getReference ().child ("Users").child (user_id);

                            databaseReference.addValueEventListener (new ValueEventListener () {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                                    //converting the json into the notification
                                    //display notification after getting the response
                                    createNotificationChannel ();

                                     //create an intent to open notification activity
                                    Intent NotificationActivity = new Intent (getActivity (), NotificationActivity.class);
                                    NotificationActivity.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                                    PendingIntent statusPendingIntent = PendingIntent.getActivity (getActivity (),0,NotificationActivity,PendingIntent.FLAG_CANCEL_CURRENT);
                                    NotificationCompat.Builder builder = new NotificationCompat.Builder (getActivity (), CHANNEL_IDcontrolnumber);
                                    builder.setSmallIcon (R.drawable.ic_near_me_black_24dp);
                                    builder.setContentTitle ("Control Number For Graduation Gown");
                                    builder.setPriority (NotificationCompat.PRIORITY_DEFAULT);
                                    builder.setAutoCancel (true);

                                    NotificationActivity.putExtra ("controlnumber","Control Number:" +studentClearance.getControlNumber () );
                                    NotificationActivity.putExtra ("reason","REASON: Graduation Gown Fee");
                                    NotificationActivity.putExtra ("department","SUA BURSAR");

                                    builder.setContentIntent (statusPendingIntent);

                                    StudentDataFirebase studentDataFirebase = dataSnapshot.getValue (StudentDataFirebase.class);
                                    String registationnumber = studentDataFirebase.getRegistrationNumber ();
                                    if(studentClearance.getRegistrationno () .equals (registationnumber))
                                    {


                                          //notification begins here
                                            Bitmap bitmap = BitmapFactory.decodeResource (getResources (), R.drawable.bursar);
                                            builder.setLargeIcon (bitmap);
                                            builder.setStyle (new NotificationCompat.InboxStyle ()

                                                                      .addLine ("Control Number: " +studentClearance.getControlNumber () )
                                                                      .setSummaryText ("SUA Bursar"));




                                            NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from (getActivity ());
                                            notificationManagerCompat.notify (NOTIFICATION_IDGownControlNumber,builder.build ());


                                        }
                                    }




                                @Override
                                public void onCancelled(@NonNull DatabaseError databaseError) {

                                    Toast.makeText (getActivity (),"OOPS an ERROR occured",Toast.LENGTH_LONG).show ();
                                }
                            });






                        }

                    }

                    @Override
                    public void onFailure(Call<List<StudentClearanceControlNumber>> call, Throwable t) {
                        Toast.makeText (getActivity (),"From OCApp " +t.getMessage (),Toast.LENGTH_LONG).show ();


                    }


                });
            }
        });

Have tried previous versions pf Retrofit but i still get nothing已经尝试过以前的版本 pf Retrofit 但我仍然一无所获

here is what it says on the log这是它在日志上所说的

D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
D/ViewRootImpl[Toast]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
D/Surface: Surface::allocateBuffers(this=0x89e11000)
D/OpenSSLLib: OpensslErr:Module:30(110:); file:external/boringssl/src/crypto/fipsmodule/cipher/cipher.c ;Line:563;Function:EVP_CIPHER_CTX_set_key_length
D/Surface: Surface::connect(this=0x89e11000,api=1)
D/Surface: Surface::disconnect(this=0x89e11000,api=1)
D/View: [Warning] assignParent to null: this = android.widget.LinearLayout{2dc2919 V.E...... ......ID 0,0-235,72}

请检查清单文件中的互联网权限。

 <uses-permission android:name="android.permission.INTERNET" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM