0

I Build My App And It Shows A Sucessfull Build But When I tried to run in my device then it shows your app keep stoping open again and this happen in only login activity if any one help me to fix this so please help me

my Login Activity Code

package com.eassycars.www.licencespot;

import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
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.ProgressBar;
import android.widget.RelativeLayout;
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 Activity_Login extends AppCompatActivity {


    private EditText inputEmail, inputPassword;
    private FirebaseAuth mAuth;
    private ProgressBar progressBar;
    private Button singups,forgotpass,logins;


    RelativeLayout really1, really2;

    Handler handler = new Handler();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            really1.setVisibility(View.VISIBLE);
            really2.setVisibility(View.VISIBLE);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Get Firebase auth instance
        mAuth = FirebaseAuth.getInstance();

        if (mAuth.getCurrentUser() != null) {
            startActivity(new Intent(Activity_Login.this, MainActivity.class));
            finish();
        }

        // set the view now
        setContentView(R.layout.activity__login);


        inputEmail = (EditText) findViewById(R.id.email);
        inputPassword = (EditText) findViewById(R.id.password);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        singups = (Button) findViewById(R.id.singups);
        logins = (Button) findViewById(R.id.logins);
        forgotpass = (Button) findViewById(R.id.forgotpass);

        //Get Firebase auth instance
        mAuth = FirebaseAuth.getInstance();

        singups.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Activity_Login.this, singup.class));
            }
        });

        forgotpass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Activity_Login.this, ForgotPassword.class));
            }
        });
        really1 = (RelativeLayout) findViewById(R.id.rellayl);
        really2 = (RelativeLayout) findViewById(R.id.really2);
        handler.postDelayed(runnable, 2000);

        logins.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String email = inputEmail.getText().toString();
                final String password = inputPassword.getText().toString();

                if (TextUtils.isEmpty(email)) {
                    Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(password)) {
                    Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
                    return;
                }

                progressBar.setVisibility(View.VISIBLE);

                //authenticate user
                mAuth.signInWithEmailAndPassword(email, password)
                        .addOnCompleteListener(Activity_Login.this, new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                // If sign in fails, display a message to the user. If sign in succeeds
                                // the auth state listener will be notified and logic to handle the
                                // signed in user can be handled in the listener.
                                progressBar.setVisibility(View.GONE);
                                if (!task.isSuccessful()) {
                                    // there was an error
                                    if (password.length() < 6) {
                                        inputPassword.setError(getString(R.string.minimum_password));
                                    } else {
                                        Toast.makeText(Activity_Login.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
                                    }
                                } else {
                                    Intent intent = new Intent(Activity_Login.this, MainActivity.class);
                                    startActivity(intent);
                                    finish();

                                }
                            }
                        });
            }
        });
    }
}

These are my login activity code and cant able to find error and android studio also shows that you don't have any error but there is an error that's my app keep stopping when i use my login screen.

I build An Login Activity using Firebase

groxx
  • 11
  • 1
  • 3
    Where is the error message or Exception trace? – Sazzadur Rahaman Jul 17 '18 at 03:56
  • please add logcat error too – masoud vali Jul 17 '18 at 04:03
  • this what i cant find it when i bult my application then its show you have sucessfull build but when i try to run apk it will run but when i try to login then and pressing login button then it shows your app keep stooping so there is a problem on login activity buy i cant find it – groxx Jul 17 '18 at 04:06
  • I think There s problem Happen With Arranging Code or if I Have Anything On Firebase Authentication – groxx Jul 17 '18 at 04:08

1 Answers1

0

Please post your error message from logcat.

If calling Handler from a Thread leads to NullPointerException,

Try to call your handler in onCreate

public class LoginActivity extends Activity {

@Override
public void onCreate(Bundle bundle){
    super.onCreate(bundle);
    //move this HERE!!  
    new Handler().post(new Runnable() {
    @Override
      public void run() {
       // Code here will run in UI thread
      }
    });
  }
}
Android
  • 1,420
  • 4
  • 13
  • 23