Could someone explain to me why this null Pointer Exception?

Asked

Viewed 148 times

0

Logcat

java.lang.Nullpointerexception: Attempt to invoke virtual method 'android.text.Editable android.widget.Edittext.gettext()' on a null Object Reference at com.paivadeveloper.megamessenger.Registeractivity$1.onClick(Registeractivity.java:49) at android.view.View.performClick(View.java:6261) at android.widget.Textview.performClick(Textview.java:11159) at android.view.View$Performclick.run(View.java:23748) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.Activitythread.main(Activitythread.java:6776) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:1496) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:1386)

Java

public class RegisterActivity extends AppCompatActivity {
private FirebaseAuth mAuth;


private TextInputLayout mDisplayName;
private TextInputLayout mEmail;
private TextInputLayout mPassword;
private Button mCreateBtn;

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

    mAuth = FirebaseAuth.getInstance();

    mDisplayName = (TextInputLayout) findViewById(R.id.reg_display_name);
    mEmail = (TextInputLayout) findViewById(R.id.reg_email);
    mPassword = (TextInputLayout) findViewById(R.id.reg_password);
    mCreateBtn = (Button) findViewById(R.id.reg_create_btn);


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

            String display_name = mDisplayName.getEditText().getText().toString();
            String email = mEmail.getEditText().getText().toString();
            String password = mPassword.getEditText().getText().toString();

            register_user(display_name, email, password);
        }
    });

}

private void register_user(String display_name, String email, String password) {

    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                startActivity(mainIntent);
                finish();
            } else {
                Toast.makeText(RegisterActivity.this, "Erro , contate-nos", Toast.LENGTH_LONG).show();
            }
        }
    });
    }

    }

Thank you

  • It seems that the findViewById is not finding the desired element for the edit

  • 1

    Yeah, I saw it, I thought it was weird because the other 2 Dit didn’t give the null Pointer Exception , very strange right

  • It seems that the is that is actually in the element is another, and not this. Absurd? It looks that way, but maybe it’s worth checking which are the element ids on the screen for debugging purposes

  • 1

    Got it here , the error was that it had Edit text out of Textinputlayout , but another kkk error appeared but it was worth by force

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.