Dear, by pressing the button that should take me to the "Registration" Activity in order to create an account, android I get the following error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.example.ksandoval.loginpro.Registro.onCreate(Registro.java:41).
I have reviewed but I do not see the error, everything is declared and instantiated correctly ... (I think). I appreciate your help in advance. Attachment XML + Class.
Activity:
public class Registro extends AppCompatActivity {
private Button btRegistro;
private EditText etUser, etEmail, etPass;
private ProgressDialog mProgress;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAuth = FirebaseAuth.getInstance();
btRegistro = (Button) findViewById(R.id.bt_registro);
etUser = (EditText) findViewById(R.id.et_userRegistro);
etEmail = (EditText) findViewById(R.id.et_correoRegistro);
etPass = (EditText) findViewById(R.id.et_passwordRegistro);
//Progreso
mProgress = new ProgressDialog(this);
//string
String name = etUser.getText().toString();
String email = etEmail.getText().toString();
String pass = etPass.getText().toString();
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)){
//Seteo la barra de progreso
mProgress.setMessage("Registering, please wait...");
mProgress.show();
//Creo el registro para FireBase
mAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
mProgress.dismiss(); //quito el Progress dialog
if (task.isSuccessful()){
String user_id = mAuth.getCurrentUser().getUid();
Toast.makeText(Registro.this, "Authentication Complete : " + user_id, Toast.LENGTH_SHORT).show();
limpiarCampos();
}else{
// If sign in fails, display a message to the user.
//Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(Registro.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
}//fin del oncreate
//Metodos Propios
public boolean validarCampos(){
try{
String user = etUser.getText().toString();
String correo = etEmail.getText().toString();
String pass = etPass.getText().toString();
if (user.isEmpty() || correo.isEmpty() || pass.isEmpty()){
Toast.makeText(this, "Tiene campos en blanco", Toast.LENGTH_SHORT).show();
return false;
}else {
return true;
}
}catch (Exception e){
Toast.makeText(this, "Error al capturar los datos " + e.toString(), Toast.LENGTH_SHORT).show();
}
return false;
}
public void limpiarCampos(){
etUser.setText("");
etEmail.setText("");
etPass.setText("");
}}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context="com.example.ksandoval.loginpro.MainActivity">
<LinearLayout
android:id="@+id/lnlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<TextView
android:id="@+id/tv_logo"
style="@style/tv_tituloStyle"
android:layout_margin="50dp"
android:text="@string/tv_logo" />
<EditText
android:id="@+id/et_userRegistro"
style="@style/et_style"
android:hint="@string/hint_userRegistro"
android:inputType="textPersonName" />
<EditText
android:id="@+id/et_correoRegistro"
style="@style/et_style"
android:hint="@string/et_correoRegistro"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/et_passwordRegistro"
style="@style/et_style"
android:hint="@string/hint_passRegistro"
android:inputType="textPassword" />
<Button
android:id="@+id/bt_registro"
style="@style/btn_style"
android:text="@string/bt_registro" />
<TextView
android:id="@+id/tv_kris"
style="@style/tv_style"
android:text="@string/tv_kris" />
</LinearLayout>
</RelativeLayout