4 Replies - 187 Views - Last Post: 18 May 2019 - 06:03 PM

#1 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

App automatically stopped when run

Posted 17 May 2019 - 11:41 PM

Hi guys, im new to the android development and was trying to follow this tutorial.
However I cant really get why the application closed automatically after running it.
The android studio platform did not give any errors however the app that I am trying to run is not working as expected.
Looking forward for somebody who can help me with this case.

Thanks

package com.example.firebase2;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class Login extends AppCompatActivity {

    private EditText mEmail;
    private EditText mPassword;
    private Button mLogin;
    private FirebaseAuth firebaseAuth;
    private FirebaseAuth.AuthStateListener mAuthStateListener;

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

        firebaseAuth = FirebaseAuth.getInstance();
        mEmail = findViewById(R.id.emailEditText);
        mPassword = findViewById(R.id.passwordEditText);
        mLogin = findViewById(R.id.loginButton);

        mAuthStateListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

                if(firebaseAuth.getCurrentUser() != null){
                    startActivity(new Intent(Login.this, Login2.class));
                }

            }
        };

        mLogin.setonclickListener(new View.onclickListener() {
            @Override
            public void onclick(View v) {
                startSignIn();
            }
        });
    }

    @Override
    protected void onstart() {
        super.onstart();
        firebaseAuth.addAuthStateListener(mAuthStateListener);
    }

    private void startSignIn () {
        String email = mEmail.getText().toString();
        String password = mPassword.getText().toString();

        if(TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
            Toast.makeText(Login.this, "Please Fill the box", Toast.LENGTH_LONG).show();
        }else {
            firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (!task.isSuccessful()) {
                        Toast.makeText(Login.this, " Login Unsuccessful", Toast.LENGTH_LONG).show();
                    }

                }
            });
        }
    }

}



Is This A Good Question/Topic? 0
  • +

Replies To: App automatically stopped when run

#2 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 55
  • View blog
  • Posts: 706
  • Joined: 23-September 15

Re: App automatically stopped when run

Posted 18 May 2019 - 12:14 AM

When application closed, there must have exception displayed on the logcat tab

This post has been edited by wseng92: 18 May 2019 - 12:24 AM

Was This Post Helpful? 1
  • +
  • -

#3 ben255   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 528
  • Joined: 09-September 13

Re: App automatically stopped when run

Posted 18 May 2019 - 05:47 PM

well then, what are you expecting to happen and what is happening? have you done all gradle implementations correcly? and permissions?
Was This Post Helpful? 0
  • +
  • -

#4 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

Re: App automatically stopped when run

Posted 18 May 2019 - 05:55 PM

This is the RunTimeException that shows after the app closed.

.RuntimeException: Unable to start activity ComponentInfo{com.example.firebase2/com.example.firebase2.Login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.firebase2. Make sure to call FirebaseApp.initializeApp(Context) first.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12648
  • View blog
  • Posts: 45,822
  • Joined: 27-December 08

Re: App automatically stopped when run

Posted 18 May 2019 - 06:03 PM

The error message is telling you what to do:

Quote

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.firebase2. Make sure to call FirebaseApp.initializeApp(Context) first.

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1