0

Good morning, I am an engineering student and I am developing an application to view and download wallpapers, but I have a problem, when I click on the button that takes me to log in, the application closes, I have already seen the LogCat and I do not understand the error. FireBase is used to store the data. The application starts in a user view, but the button gives you the option to access as an administrator through a login, and that is the button that is causing problems.

This is the MainActivity Login

public class Login extends AppCompatActivity {
    EditText Correo, Contraseña;
    Button Acceder;


    FirebaseAuth firebaseAuth;
    ProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


            ActionBar actionBar = getSupportActionBar();
            assert actionBar != null;
            actionBar.setTitle("Inicio Sesión");
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);

            Correo = findViewById(R.id.Correo);
            Contraseña = findViewById(R.id.Contraseña);
            Acceder = findViewById(R.id.Acceder);

            firebaseAuth = FirebaseAuth.getInstance();

            progressDialog = new ProgressDialog(Login.this);
            progressDialog.setMessage("Ingresando, espere por favor");
            progressDialog.setCancelable(false);

            Acceder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String correo = Correo.getText().toString();
                    String contraseña = Contraseña.getText().toString();


                    if (!Patterns.EMAIL_ADDRESS.matcher(correo).matches()) {

                        Correo.setError("Correo Invalido");
                        Correo.setFocusable(true);

                    } else if (contraseña.length() < 6) {

                        Contraseña.setError("Contraseña debe ser mayor o igual a 6 digitos");
                        Contraseña.setFocusable(true);
                    } else {
                        LogeoAdministradores(correo, contraseña);
                    }
                }
            });
        }

        private void LogeoAdministradores (String correo, String contraseña){
            progressDialog.show();
            progressDialog.setCancelable(false);
            firebaseAuth.signInWithEmailAndPassword(correo,contraseña)
                    .addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful()){
                                progressDialog.dismiss();
                                FirebaseUser user = firebaseAuth.getCurrentUser();
                                startActivity(new Intent(Login.this,MainActivityAdministrador.class));
                                assert user != null;
                                Toast.makeText(Login.this, "Bienvenido (a)" +user.getEmail(), Toast.LENGTH_SHORT).show();
                                finish();
                            }else{
                                progressDialog.dismiss();
                                UsuarioInvalido();
                            }
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            progressDialog.dismiss();
                            UsuarioInvalido();

                        }
                    });
        }

        private void UsuarioInvalido() {
            AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
            builder.setCancelable(false);
            builder.setTitle("Ha ocurrido un error");
            builder.setMessage("Verifique si el correo o contraseña son correctos")
                    .setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    }).show();
        }

        @Override
        public boolean onSupportNavigateUp() {
            onBackPressed();
            return super.onSupportNavigateUp();
        }

}

And this is the error that appears in the LogCat

2022-10-21 08:56:52.718 29357-29357/com.example.wallpaper_community E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.wallpaper_community, PID: 29357
    java.lang.AssertionError
        at com.example.wallpaper_community.Login.onCreate(Login.java:39)
        at android.app.Activity.performCreate(Activity.java:8214)
        at android.app.Activity.performCreate(Activity.java:8202)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8668)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
2022-10-21 08:56:52.737 29357-29357/com.example.wallpaper_community I/Process: Sending signal. PID: 29357 SIG: 9

I hope you can help me, in advance thank you very much for your attention and have a great day.

4
  • check assert actionBar != null; in Login#onCreate. Are you using a NoActionBar theme?
    – Ayaka_Ago
    Commented Oct 22, 2022 at 3:26
  • In a Manifest? Yes I using NoActionBar
    – Juan
    Commented Oct 22, 2022 at 14:08
  • You should use a theme with ActionBar to let actionBar not null.
    – Ayaka_Ago
    Commented Oct 22, 2022 at 17:41
  • So it's an Android issue rather than a Firebase one, right?
    – Alex Mamo
    Commented Oct 26, 2022 at 14:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.