Can't create PhoneAuthCredential without verif. proof, session info, temp. proof, or enroll. ID

I’m working on Firebase phone authentication and facing an error when trying to create a PhoneAuthCredential in the verifySignInCode() method.

This is my code for sending the code:

public void send_code(){
    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            super.onCodeSent(s, forceResendingToken);
            Log.d("code", "onCodeSent:" + s);
            verificationID=s;
        }
        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {

        }
        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            Toast.makeText(PhoneAuthentication.this, e.getMessage(), Toast.LENGTH_SHORT);
        }
    };
    mPhoneAuthProvider.verifyPhoneNumber(
            user_contact , 60, TimeUnit.SECONDS, PhoneAuthentication.this, mCallbacks
    );
}

This is my code for verifying the sign in code:

public void verifySignInCode(String code){
    try {
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationID, code);
        signInWithPhoneAuthCredential(credential);
    }catch (Exception e){
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();

    }
}

This is my code for signing in with phone credentials:

private  void signInWithPhoneAuthCredential(PhoneAuthCredential credential){
    mFirebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){

                        startActivity(new Intent(PhoneAuthentication.this, UserHome.class));
                    }
                    else {
                        Log.d("error:", task.getException().getMessage());

                    }
                }
            });
}

I’m getting the following error when trying to create a PhoneAuthCredential in the verifySignInCode() method:

Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.

Add verificationID as a null check before creating the PhoneAuthCredential in the verifySignInCode() method.

Here’s the updated code:

public void verifySignInCode(String code){
    try {
        if (verificationID != null) {
            PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationID, code);
            signInWithPhoneAuthCredential(credential);
        } else {
            Toast.makeText(getApplicationContext(), "Verification ID is null", Toast.LENGTH_SHORT).show();
        }
    }catch (Exception e){
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}