I was trying to do a simple firebase register new user
what I did :
added the fire base json file after registered the app with its domain here :
https://firebase.google.com/
added <uses-permission android:name="android.permission.INTERNET" /> to the manifest
added classpath 'com.google.gms:google-services:4.0.0' to gradle.build project
added implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-auth:9.2.1'
and
apply plugin: 'com.google.gms.google-services' to gradle.build(module:app)
so it looked like this :
main xml :
main java :
I get errors for the java:
1 AuthResult cannot resolve symbol
2 task.isSuccessful() cannot resolve methode
3 even if I try to run :
firebaseAuth.createUserWithEmailAndPassword(email, password);
I get an error :
cannot access zzaltclass file
what I did :
added the fire base json file after registered the app with its domain here :
https://firebase.google.com/
added <uses-permission android:name="android.permission.INTERNET" /> to the manifest
added classpath 'com.google.gms:google-services:4.0.0' to gradle.build project
added implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-auth:9.2.1'
and
apply plugin: 'com.google.gms.google-services' to gradle.build(module:app)
so it looked like this :
Code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.justforum.yotamarker.fb3"
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-auth:9.2.1'
}
apply plugin: 'com.google.gms.google-services'
main xml :
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter password"
android:inputType="textPassword" />
<Button
android:id="@+id/buttonSignup"
android:onClick="registerClick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Signup" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
main java :
Code:
package com.justforum.yotamarker.fb3;
import android.app.ProgressDialog;
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.Toast;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity {
private EditText editTextEmail;
private EditText editTextPassword;
private Button buttonSignup;
private ProgressDialog progressDialog;
//defining firebaseauth object
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
//initializing views
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
progressDialog = new ProgressDialog(this);
}
private void registerUser(){
//getting email and password from edit texts
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//checking if email and passwords are empty
if(TextUtils.isEmpty(email)){
Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
return;
}
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Registering Please Wait...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//checking if success
if(task.isSuccessful()){
//display some message here
Toast.makeText(MainActivity.this,"Successfully registered",Toast.LENGTH_LONG).show();
}else{
//display some message here
Toast.makeText(MainActivity.this,"Registration Error",Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
public void registerClick(View view) {
registerUser();
}
}
I get errors for the java:
1 AuthResult cannot resolve symbol
2 task.isSuccessful() cannot resolve methode
3 even if I try to run :
firebaseAuth.createUserWithEmailAndPassword(email, password);
I get an error :
cannot access zzaltclass file