Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java.lang.IllegalArgumentException:给定字符串为空或null(Firebase PhoneAuth)_Android_Firebase_Firebase Authentication - Fatal编程技术网

Android java.lang.IllegalArgumentException:给定字符串为空或null(Firebase PhoneAuth)

Android java.lang.IllegalArgumentException:给定字符串为空或null(Firebase PhoneAuth),android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,我正在开发一个应用程序,需要firebase身份验证电话验证 我已在Firebase中检查PhoneAuth权限 我已经在firebase检查了sha-1证书 我还检查了项目中Firebase的依赖关系 每件事情都设置正确 这就是我面临的错误 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInf

我正在开发一个应用程序,需要firebase身份验证电话验证

我已在Firebase中检查PhoneAuth权限 我已经在firebase检查了sha-1证书 我还检查了项目中Firebase的依赖关系

每件事情都设置正确

这就是我面临的错误

java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
        at android.view.View.performClick(View.java:5269)
        at android.view.View$PerformClick.run(View.java:21548)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5740)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
        at android.view.View.performClick(View.java:5269) 
        at android.view.View$PerformClick.run(View.java:21548) 
        at android.os.Handler.handleCallback(Handler.java:815) 
        at android.os.Handler.dispatchMessage(Handler.java:104) 
        at android.os.Looper.loop(Looper.java:207) 
        at android.app.ActivityThread.main(ActivityThread.java:5740) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:766) 
     Caused by: java.lang.IllegalArgumentException: Given String is empty or null
        at com.google.android.gms.common.internal.zzbq.zzgm(Unknown Source)
        at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown Source)
        at com.bhai.paras.kisansewa.SignIn.SignInClicked(SignIn.java:90)
这是密码

登录方法

public void SignInClicked(View v) {

           // Intent intent=new Intent(SignIn.this,FarmerProfile.class);
            //startActivity(intent);
            String Username=name.getText().toString().trim();
            String  Number= number.getText().toString().trim();
            if(Username.isEmpty() || Number.isEmpty())
            {
                Snackbar.make(c,"Enter Each Field",Snackbar.LENGTH_SHORT).show();
            }
            else if(Number.length()>10 || Number.length()<10)
            {

                Snackbar.make(c,"Invalid Number",Snackbar.LENGTH_SHORT).show();
            }
            else
            {
                PhoneAuthProvider.getInstance().verifyPhoneNumber(
                        UserCode,      // Phone number to verify
                        60,                 // Timeout duration
                        TimeUnit.SECONDS,   // Unit of timeout
                        SignIn.this,  // Activity (for callback binding)
                        mCallbacks);        // OnVerificationStateChangedCallbacks

                mCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                    @Override
                    public void onVerificationCompleted( PhoneAuthCredential phoneAuthCredential ) {


                    }

                    @Override
                    public void onVerificationFailed( FirebaseException e ) {

                    }

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



                final Dialog myDialog = new Dialog(SignIn.this);
                myDialog.setContentView(R.layout.card_verification);
                myDialog.setCancelable(false);
                VerificationCode=(EditText)myDialog.findViewById(R.id.editText5);
                myDialog.findViewById(R.id.buttonn).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick( View v ) {
                        String ss=VerificationCode.getText().toString();
                        if(ss.isEmpty())
                        {
                            Toast.makeText(SignIn.this,"Enter Verification code",Toast.LENGTH_SHORT).show();
                        }
                        else
                        {   credential=PhoneAuthProvider.getCredential(VerificationId,ss);
                            signInWithPhoneAuthCredential(credential);
                            Dialog mDialog=new Dialog(SignIn.this);
                            mDialog.setContentView(R.layout.signing);
                            mDialog.setCancelable(false);
                            mDialog.show();
                            myDialog.cancel();

                        }

                    }
                });
                myDialog.show();
            }

        }

        public void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
            mAuth.signInWithCredential(credential)
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful())
                            {
                                myRef.child(number.getText().toString()).child("Name").setValue(name.getText().toString());
                                myRef.child(number.getText().toString()).child("VerificationId").setValue(VerificationId);
                                myRef.child(number.getText().toString()).child("Code").setValue(code);
                                myRef.child(number.getText().toString()).child("Category").setValue(Category);
                                if(Category.equals("Farmer"))
                                {
                                    Intent intent=new Intent(SignIn.this,FarmerProfile.class);
                                    startActivity(intent);
                                    finish();
                                }
                                else if(Category.equals("Buyer"))
                                {
                                    Intent intent=new Intent(SignIn.this,BuyersProfile.class);
                                    startActivity(intent);
                                    finish();
                                }

                            } else {
                                // Sign in failed, display a message and update the UI
                                Log.w("TAG", "signInWithCredential:failure", task.getException());
                                if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                    // The verification code entered was invalid
                                    Snackbar.make(c,"Invalid Verification Code Entered",Snackbar.LENGTH_SHORT).show();

                                }
                            }
                        }
                    });
        }
注意用户代码=用户输入的编号。

已选中公共作废标志(视图v){
public void SignInClicked(View v) {
       // Intent intent=new Intent(SignIn.this,FarmerProfile.class);
        //startActivity(intent);
        String Username=name.getText().toString().trim();
        String  Number= number.getText().toString().trim();
        if(Username.isEmpty() || Number.isEmpty())
        {
            Snackbar.make(c,"Enter Each Field",Snackbar.LENGTH_SHORT).show();
        }
        else if(Number.length()>10 || Number.length()<10)
        {

            Snackbar.make(c,"Invalid Number",Snackbar.LENGTH_SHORT).show();
        }
        else
        {
            PhoneAuthProvider.getInstance().verifyPhoneNumber(
                    UserCode,      // Phone number to verify
                    60,                 // Timeout duration
                    TimeUnit.SECONDS,   // Unit of timeout
                    SignIn.this,  // Activity (for callback binding)
                    mCallbacks);        // OnVerificationStateChangedCallbacks

            mCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                @Override
                public void onVerificationCompleted( PhoneAuthCredential phoneAuthCredential ) {

                // show dialog here

                 final Dialog myDialog = new Dialog(SignIn.this);
            myDialog.setContentView(R.layout.card_verification);
            myDialog.setCancelable(false);
            VerificationCode=(EditText)myDialog.findViewById(R.id.editText5);
            myDialog.findViewById(R.id.buttonn).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick( View v ) {
                    String ss=VerificationCode.getText().toString();
                    if(ss.isEmpty())
                    {
                        Toast.makeText(SignIn.this,"Enter Verification code",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {   credential=PhoneAuthProvider.getCredential(VerificationId,ss);

                        // pass here phoneauthcredntial
                       // signInWithPhoneAuthCredential(credential);


                        Dialog mDialog=new Dialog(SignIn.this);
                        mDialog.setContentView(R.layout.signing);
                        mDialog.setCancelable(false);
                        mDialog.show();
                        myDialog.cancel();

                    }

                }
            });
            myDialog.show();

                }

                @Override
                public void onVerificationFailed( FirebaseException e ) {

                // catch ur exception e

                }

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




        }

    }

    public void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful())
                        {
                            myRef.child(number.getText().toString()).child("Name").setValue(name.getText().toString());
                            myRef.child(number.getText().toString()).child("VerificationId").setValue(VerificationId);
                            myRef.child(number.getText().toString()).child("Code").setValue(code);
                            myRef.child(number.getText().toString()).child("Category").setValue(Category);
                            if(Category.equals("Farmer"))
                            {
                                Intent intent=new Intent(SignIn.this,FarmerProfile.class);
                                startActivity(intent);
                                finish();
                            }
                            else if(Category.equals("Buyer"))
                            {
                                Intent intent=new Intent(SignIn.this,BuyersProfile.class);
                                startActivity(intent);
                                finish();
                            }

                        } else {
                            // Sign in failed, display a message and update the UI
                            Log.w("TAG", "signInWithCredential:failure", task.getException());
                            if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                                Snackbar.make(c,"Invalid Verification Code Entered",Snackbar.LENGTH_SHORT).show();

                            }
                        }
                    }
                });
    }
//意向意向=新意向(签名:this,FarmerProfile.class); //星触觉(意向); 字符串Username=name.getText().toString().trim(); 字符串编号=Number.getText().toString().trim(); if(Username.isEmpty()| | Number.isEmpty()) { Snackbar.make(c,“输入每个字段”,Snackbar.LENGTH_SHORT.show(); }
否则,如果(Number.length()>10 | | Number.length()在哪一行出现此错误?PhoneAuthProvider.get Instance是否确实
UserCode
不是
null
?是的,我已使用断点对其进行了检查
public void SignInClicked(View v) {
       // Intent intent=new Intent(SignIn.this,FarmerProfile.class);
        //startActivity(intent);
        String Username=name.getText().toString().trim();
        String  Number= number.getText().toString().trim();
        if(Username.isEmpty() || Number.isEmpty())
        {
            Snackbar.make(c,"Enter Each Field",Snackbar.LENGTH_SHORT).show();
        }
        else if(Number.length()>10 || Number.length()<10)
        {

            Snackbar.make(c,"Invalid Number",Snackbar.LENGTH_SHORT).show();
        }
        else
        {
            PhoneAuthProvider.getInstance().verifyPhoneNumber(
                    UserCode,      // Phone number to verify
                    60,                 // Timeout duration
                    TimeUnit.SECONDS,   // Unit of timeout
                    SignIn.this,  // Activity (for callback binding)
                    mCallbacks);        // OnVerificationStateChangedCallbacks

            mCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                @Override
                public void onVerificationCompleted( PhoneAuthCredential phoneAuthCredential ) {

                // show dialog here

                 final Dialog myDialog = new Dialog(SignIn.this);
            myDialog.setContentView(R.layout.card_verification);
            myDialog.setCancelable(false);
            VerificationCode=(EditText)myDialog.findViewById(R.id.editText5);
            myDialog.findViewById(R.id.buttonn).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick( View v ) {
                    String ss=VerificationCode.getText().toString();
                    if(ss.isEmpty())
                    {
                        Toast.makeText(SignIn.this,"Enter Verification code",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {   credential=PhoneAuthProvider.getCredential(VerificationId,ss);

                        // pass here phoneauthcredntial
                       // signInWithPhoneAuthCredential(credential);


                        Dialog mDialog=new Dialog(SignIn.this);
                        mDialog.setContentView(R.layout.signing);
                        mDialog.setCancelable(false);
                        mDialog.show();
                        myDialog.cancel();

                    }

                }
            });
            myDialog.show();

                }

                @Override
                public void onVerificationFailed( FirebaseException e ) {

                // catch ur exception e

                }

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




        }

    }

    public void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful())
                        {
                            myRef.child(number.getText().toString()).child("Name").setValue(name.getText().toString());
                            myRef.child(number.getText().toString()).child("VerificationId").setValue(VerificationId);
                            myRef.child(number.getText().toString()).child("Code").setValue(code);
                            myRef.child(number.getText().toString()).child("Category").setValue(Category);
                            if(Category.equals("Farmer"))
                            {
                                Intent intent=new Intent(SignIn.this,FarmerProfile.class);
                                startActivity(intent);
                                finish();
                            }
                            else if(Category.equals("Buyer"))
                            {
                                Intent intent=new Intent(SignIn.this,BuyersProfile.class);
                                startActivity(intent);
                                finish();
                            }

                        } else {
                            // Sign in failed, display a message and update the UI
                            Log.w("TAG", "signInWithCredential:failure", task.getException());
                            if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                                Snackbar.make(c,"Invalid Verification Code Entered",Snackbar.LENGTH_SHORT).show();

                            }
                        }
                    }
                });
    }