Answer the question
In order to leave comments, you need to log in
Why is the error "Unfortunate, has stopped" displayed?
Good day. I recently started working on firebase and launched the project. But I got an error Unfortunately MyApplication,has stopped. Here is the code:
package com.example.admin.myapplicatio;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnAdd, btnRead, btnClear;
EditText etName, etEmail;
DBHelper dbHelper;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private EditText ETemail;
private EditText ETpassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user != null){
}else{
}
}
};
ETemail = (EditText) findViewById(R.id.et_email);
ETpassword = (EditText) findViewById(R.id.et_password);
findViewById(R.id.btn_sign_in).setOnClickListener(this);
findViewById(R.id.btn_registration).setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(view.getId() == R.id.btn_sign_in)
{
signin(ETemail.getText().toString(),ETpassword.getText().toString());
}else if (view.getId() == R.id.btn_registration)
{
registration(ETemail.getText().toString(),ETpassword.getText().toString());
}
}
public void signin(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, "Aвторизация успешна", Toast.LENGTH_SHORT).show();
}else
Toast.makeText(MainActivity.this, "Aвторизация провалена", Toast.LENGTH_SHORT).show();
}
});
}
public void registration (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();
}
});
}
}
package com.example.admin.myapplicatio;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHelper extends SQLiteOpenHelper{
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "contactDb";
public static final String TABLE_CONTACTS = "contacts";
public static final String KEY_ID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_MAIL = "mail";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CONTACTS + "(" + KEY_ID
+ " integer primary key," + KEY_NAME + " text," + KEY_MAIL + " text" + ")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + TABLE_CONTACTS);
onCreate(db);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_authentication"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:layout_width="250dp"
android:layout_height="50dp"
android:id="@+id/et_email"
android:layout_centerHorizontal="true"
android:layout_marginTop="145dp"
android:hint="Email"
android:textColorHint="@color/colorPrimary"
android:textSize="30dp"/>
<EditText android:layout_width="250dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/et_email"
android:hint="Password"
android:textColorHint="@color/colorPrimary"
android:textSize="30dp"
android:id="@+id/et_password"
/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_password"
android:layout_marginTop="20dp"
>
<Button android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Авторизация"
android:layout_weight="1"
android:id="@+id/btn_sign_in"/>
<Button android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Регистрация"
android:id="@+id/btn_registration"/>
</LinearLayout>
</RelativeLayout>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question