运行我的应用时,“字符串为空或空”

时间:2019-12-18 15:11:07

标签: authentication

运行我的应用程序时,会弹出此错误:

  

E / Android运行时:致命异常:主要       流程:com.example.mymainapp,PID:10811      java.lang.IllegalArgumentException:给定的String为空或null           com.google.android.gms.common.internal.Preconditions.checkNotEmpty处(未知来源:5)           com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword处(未知来源:199)           在com.example.mymainapp.MainActivity.validate(MainActivity.java:77)           在com.example.mymainapp.MainActivity.access $ 200(MainActivity.java:23)           在com.example.mymainapp.MainActivity $ 1.onClick(MainActivity.java:55)           在android.view.View.performClick(View.java:7352)           在android.widget.TextView.performClick(TextView.java:14177)           在android.view.View.performClickInternal(View.java:7318)           在android.view.View.access $ 3200(View.java:846)           在android.view.View $ PerformClick.run(View.java:27800)           在android.os.Handler.handleCallback(Handler.java:873)           在android.os.Handler.dispatchMessage(Handler.java:99)           在android.os.Looper.loop(Looper.java:214)           在android.app.ActivityThread.main(ActivityThread.java:7050)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

这是我的代码(MainActivity):

public class MainActivity extends AppCompatActivity {

    private TextView InicioDeSes, NuevaCuenta;
    private EditText CorreoEletric, Contrasena;
    private Button IniciarSesion;
    private FirebaseAuth firebaseAuth;
    private ProgressDialog progressDialog;

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

        CorreoEletric = findViewById(R.id.etCorreoEletr);
        Contrasena = findViewById(R.id.etPassword);
        IniciarSesion = findViewById(R.id.btnEntrar);
        InicioDeSes = findViewById(R.id.tvIniciarSesión);
        NuevaCuenta = findViewById(R.id.tvNuevaCuenta);
        firebaseAuth = FirebaseAuth.getInstance();
        progressDialog = new ProgressDialog(this);

        FirebaseUser user = firebaseAuth.getCurrentUser();

        if(user != null){
            finish();
            startActivity(new Intent(MainActivity.this, HomeActivity.class));
        }


        IniciarSesion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                validate(CorreoEletric.getText().toString(), Contrasena.getText().toString());
            }
        });


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

                moveToRegisterActivity();
            }
        });

    }


    private void validate(String CorreoEletric, String Contrasena) {

        progressDialog.setMessage("Aguarde, estamos verificando tu cuenta!");
        progressDialog.show();

        firebaseAuth.signInWithEmailAndPassword(CorreoEletric, Contrasena).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if(task.isSuccessful()){
                    progressDialog.dismiss();
                    startActivity(new Intent(MainActivity.this, HomeActivity.class));
                }else{
                    progressDialog.dismiss();
                    Toast.makeText(MainActivity.this, "Algo ha fallado al iniciar sesión, por favor verifique los campos", Toast.LENGTH_LONG).show();
                }
            }
        });

    }

    private void moveToRegisterActivity(){

        Intent intent = new Intent(MainActivity.this, registrationActivity.class);
        startActivity(intent);
    }
}

这不是API KEY,我已经检查过了。另外,当我按下按钮(tvIniciarSesión)登录应用程序时,会出现错误,该应用程序崩溃。

0 个答案:

没有答案