Reputation: 123
I have a problem in this code that why every time it is showing registration error after filling the form and ids are fine but I dont know what is wrong with this code.Errors are here!! how i can fix it.Please help me !! Thanks
public class reg2activity extends AppCompatActivity {
EditText emailvariable;
EditText passvariable;
Button regvariable;
FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reg2activity);
firebaseAuth=FirebaseAuth.getInstance();
emailvariable=(EditText)findViewById(R.id.regemailid);
passvariable=(EditText)findViewById(R.id.regpassid);
regvariable=(Button)findViewById(R.id.Regloginid);
regvariable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
userReg();
}
});
}
public void userReg() {
String emailstring=emailvariable.getText().toString();
String passstring=passvariable.getText().toString();
firebaseAuth.createUserWithEmailAndPassword(emailstring,passstring).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(reg2activity.this,"Regestration successful",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(reg2activity.this,"Regestration error",Toast.LENGTH_LONG).show();
}
}
});
The error message I got is:
07-16 14:09:09.281 2780-2780/com.example.avc.homeproject
W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
07-16 14:09:09.501 2780-2780/com.example.avc.homeproject W/System.err:
com.google.firebase.FirebaseNetworkException: A network error (such as
timeout, interrupted connection or unreachable host) has occurred.
at com.google.android.gms.internal.zzdvf.zzap(Unknown Source)
07-16 14:09:09.511 2780-2780/com.example.avc.homeproject W/System.err:
at
com.google.android.gms.internal.zzduh.zza(Unknown Source)
at com.google.android.gms.internal.zzdvq.zzaq(Unknown Source)
at com.google.android.gms.internal.zzdvt.onFailure(Unknown Source)
at com.google.android.gms.internal.zzdvh.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:433)
at dalvik.system.NativeStart.run(Native Method)
Upvotes: 1
Views: 2042
Reputation: 1606
There can be multiple reasons.
In your AndroidManifest.xml add permissions for INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE.
It can also happen when google play services are not running. Try to launch play store and check if it is working. If not reboot of device issue.And also compare the google play services using in the project and google play services in the device are same if not update google play services. This is just a minor but possible case where it gives the exception.
Upvotes: 2
Reputation: 37404
The common issues can be
First: Authentication is not enabled so do
Enable Email/Password sign-in:
a. In the Firebase console, open the Auth section.
b. On the Sign in method tab, enable the Email/password sign-in method and click Save.
Second: The email is not valid or password is not Strong enough e.g
Email Password Valid
[email protected] 123Ab! Yes
ab.com 123Ab! invalid email
[email protected] 12345 weak password
Third : don't reuse the same email
and to know more, catch the exception and print it
firebaseAuth.createUserWithEmailAndPassword(emailstring,passstring).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(reg2activity.this,"Regestration successful",Toast.LENGTH_LONG).show();
}
else
{
task.getException().printStackTrace();
// add this ^^^^^^^^^^^^^^^^^^^^^^^
Toast.makeText(reg2activity.this,"Regestration error",Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 1