public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText email;
private EditText password;
//Это создавать обязательно
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
mAuth.createUserWithEmailAndPassword(email.getText().toString(),password.getText().toString())
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
} else {
}
}
});
}
private void init() {
email = findViewById(R.id.email);
password = findViewById(R.id.password);
mAuth = FirebaseAuth.getInstance();
}
@Override
public void onClick(View v) {
//Если мы нажали на кнопку с id LogIn сработает определенное условие
if(v.getId() == R.id.LogIn){
LogInReg(email.getText().toString(),password.getText().toString());
}else if(v.getId() == R.id.SigIn){
SingIn(email.getText().toString(),password.getText().toString());
}
}
public void SingIn(String email, String password) {
//Слушатель для выполненого кода
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
//Вроде сработает если авторицация прошла
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//Если таск завершиться успешно
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Авторизация прошла успешно!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Авторизация не прошла ", Toast.LENGTH_SHORT).show();
}
}
});
}
public void LogInReg(String email, String password){
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Регистрация прошла успешно!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Регистрация не прошла ", Toast.LENGTH_SHORT).show();
}
}
});
}
}
Это в logocat(это все выделено красным):
11-15 17:54:13.505 30550-30550/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.english_day, PID: 30550 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.english_day/com.example.english_day.MainActivity}: java.lang.IllegalArgumentException: Given String is empty or null at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769) at android.app.ActivityThread.access$900(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) Caused by: java.lang.IllegalArgumentException: Given String is empty or null at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@17.1.0:5) at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(com.google.firebase:firebase-auth@@20.0.0:292) at com.example.english_day.MainActivity.onCreate(MainActivity.java:42) at android.app.Activity.performCreate(Activity.java:6178) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769) at android.app.ActivityThread.access$900(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)