Сбой приложения после входа в систему с помощью otp один раз, а затем после выхода из системы при попытке go снова войти на страницу - PullRequest
1 голос
/ 23 апреля 2020

Приложение остановлено. Снова откройте приложение.

Это моя процедура регистрации, в которой у меня есть поля номера телефона и пароля. После их заполнения пользователь нажимает кнопку входа, которая перенаправляет пользователя на страницу подтверждения otp.

public class SignUp extends google_abstract {

    ImageView imageView4;
    ImageView imageView5;
    ImageView imageView6;
    TextView textView13;
    EditText phone_no;
    Button sign_up;
    EditText password;

    FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
            if (firebaseUser != null) {
                Intent intent = new Intent(SignUp.this, verify_otp.class);
                startActivity(intent);
                finish();
            }
        }
    };

    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

    @Override
    protected void onStart() {
        super.onStart();
        firebaseAuth.addAuthStateListener(authStateListener);
    }

    @Override
    protected void onStop() {
        super.onStop();
        firebaseAuth.removeAuthStateListener(authStateListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);

        imageView4 = findViewById(R.id.imageView4);

        imageView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                signIn();
            }
        });

        textView13 = findViewById(R.id.textView13);

        phone_no = findViewById(R.id.editText);

        password = findViewById(R.id.editText2);

        textView13.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SignUp.this,verify_otp.class);
                startActivity(intent);
            }
        });

        sign_up = findViewById(R.id.button1);
        sign_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String number = phone_no.getText().toString().trim();
                String pass = password.getText().toString();

                if(number.isEmpty()||number.length()<10) {
                    phone_no.setError("Valid Number is required");
                    phone_no.requestFocus();
                    return;
                }
                else if( (pass.length()<8 || pass.length()>12) ){
                    password.setError("must contain min 8 and max 12 characters");
                    password.requestFocus();
                }
                else {
                    String ph_no = "+91"+number;
                    Intent intent = new Intent(SignUp.this, verify_otp.class);
                    intent.putExtra("ph_no", ph_no);
                    startActivity(intent);
                }
            }
        });
    }
}

Это мое действие verify_otp, где ввод otp и затем пользователь переходит к раздел профиля:

public class verify_otp extends AppCompatActivity {

    EditText otp;
    Button button3;
    private String verificationId;
    ProgressBar progressBar_otp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.verify_otp);

        // rsnd = findViewById(R.id.rsnd);

        String phoneNumber = getIntent().getStringExtra("ph_no");
        sendVerificationCode(phoneNumber);

        otp = findViewById(R.id.editText3);
        button3 = findViewById(R.id.button3);
        progressBar_otp = findViewById(R.id.progressBar_otp);

        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String code = otp.getText().toString().trim();

                if(code.isEmpty()||code.length()<6){
                    otp.setError("Enter code...");
                    otp.requestFocus();
                    return;
                }

                progressBar_otp.setVisibility(View.VISIBLE);
                verifyCode(code);
            }
        });

    }


    private void sendVerificationCode(String phoneNumber){
        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,
                60,
                TimeUnit.SECONDS,
                TaskExecutors.MAIN_THREAD,
                mCallBack);
    }

    private PhoneAuthProvider.OnVerificationStateChangedCallbacks
            mCallBack = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            super.onCodeSent(s, forceResendingToken);
            verificationId=s;
        }

        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {

            String code = phoneAuthCredential.getSmsCode();
            if(code!=null){
                progressBar_otp.setVisibility(View.VISIBLE);
                verifyCode(code);
            }
        }

        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            Toast.makeText(verify_otp.this,e.getMessage(),Toast.LENGTH_LONG);
        }

    };

        private void verifyCode(String code) {
            PhoneAuthCredential credential= PhoneAuthProvider.getCredential(verificationId,code);
            signInWithCredential(credential);
        }


    private void signInWithCredential(PhoneAuthCredential credential){

        FirebaseAuth mAuth = FirebaseAuth.getInstance();

        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(verify_otp.this ,new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()){
                            Intent intent= new Intent(verify_otp.this, tags.class);
                            intent.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK));

                            startActivity(intent);
                        }
                        else{
                            Toast.makeText(verify_otp.this, task.getException().getMessage(),Toast.LENGTH_LONG);
                        }
                    }
                });
     }
}

Это нормально работает в первый раз, когда пользователь устанавливает это приложение, но происходит сбой после того, как пользователь пытается go войти в Activity.

LogCat показывает следующие исключения:

2020-04-23 21:17:04.625 23151-23151/com.sneha.blackcoffer I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/lib/arm, /system/lib, /system/vendor/lib]]
2020-04-23 21:17:04.627 23151-23151/com.sneha.blackcoffer I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/lib/arm, /system/lib, /system/vendor/lib]]
2020-04-23 21:17:04.628 23151-23151/com.sneha.blackcoffer I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.sneha.blackcoffer-RQhqJvhXDK8dcBsMOKlvsQ==/lib/arm, /system/lib, /system/vendor/lib]]
2020-04-23 21:17:04.761 23151-23151/com.sneha.blackcoffer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sneha.blackcoffer, PID: 23151
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sneha.blackcoffer/com.sneha.blackcoffer.verify_otp}: java.lang.IllegalArgumentException: Given String is empty or null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2974)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
     Caused by: java.lang.IllegalArgumentException: Given String is empty or null
        at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@17.1.1:5)
        at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(com.google.firebase:firebase-auth@@19.3.0:13)
        at com.sneha.blackcoffer.verify_otp.sendVerificationCode(verify_otp.java:73)
        at com.sneha.blackcoffer.verify_otp.onCreate(verify_otp.java:47)
        at android.app.Activity.performCreate(Activity.java:7258)
        at android.app.Activity.performCreate(Activity.java:7249)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:7000) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 

Строка 47 - это sendVerificationCode (phoneNumber);

, а строка 73 - это PhoneAuthProvider.getInstance (). VerifyPhoneNumber (

1 Ответ

0 голосов
/ 23 апреля 2020

Причина: java .lang.IllegalArgumentException: Данная строка пуста или равна нулю

Похоже, строка phoneNumber пуста или равна нулю. Вы должны проверить это через TextUtils.isEmpty().

 String phoneNumber = getIntent().getStringExtra("ph_no");
 if(!TextUtils.isEmpty(phoneNumber))
 {
  sendVerificationCode(phoneNumber);
 }
 else
 {
  //Print your phone number is null or empty
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...