-1

The code below runs however when I go to run the application in an android emulator the application will open then close immediately .I am an android programming beginner thankyou

the code in question is below

    login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String emailString =email.getText().toString();
            String pwd =password.getText().toString();

            if(!emailString.equals("")&& !pwd.equals("")){
                mAuth.signInWithEmailAndPassword(emailString,pwd)
                        .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if(!task.isSuccessful()){
                                    Toast.makeText(MainActivity.this,"Unrecognised Credentials",Toast.LENGTH_LONG).show();
                                } else { Toast.makeText  
          (MainActivity.this,"recognised  Credentials",Toast.LENGTH_LONG).show();  

                                }
                            }
                        });
            }

    @Override
    protected void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);


    }

    @Override
    protected void onStop() {
    super.onStop();

    if(mAuthListener != null){
        mAuth.removeAuthStateListener(mAuthListener);
     }
     }
     }
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
Daniel
  • 23
  • 5

2 Answers2

1

Initialize FirebaseAuth.and put .json file in app folder

mFirebaseAuth = FirebaseAuth.getInstance();
sk sakil
  • 186
  • 1
  • 12
0

Make sure your loginActivity or MainActivity, whatever. That is define in AndroidManifest file. and check onCreate method again, is there any syntax mistake.

Saq
  • 21
  • 4
  • i do have syntax errors but am unsure of how to resolve the issue the errors are in this bit of code – Daniel Mar 22 '18 at 12:20
  • Where it shows error, put cursor on it. It shows the correction of syntax. Or click there and a yellow or red bulb appear on left side of code screen then tell me what it shows. – Saq Mar 22 '18 at 12:29
  • the syntax error is right at the bottom of the code and it displays );}}}} as what is needed I have tried this and it still does not work – Daniel Mar 22 '18 at 14:09