我在这段代码中有一个问题,为什么每次在填写表格和ID后显示注册错误都可以,但是我不知道这段代码有什么问题,错误在这里!我该如何解决。请帮助我!谢谢
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();
}
}
});
我收到的错误消息是:
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)
答案 0 :(得分:2)
可以有多个reasons。
在您的AndroidManifest.xml中添加INTERNET,ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE的权限。
当Google Play服务未运行时,也会发生这种情况。尝试启动Play商店并检查其是否正常运行。如果没有重启设备问题。并且还比较了项目中使用的Google Play服务和设备中的Google Play服务,如果未更新Google Play服务则相同。 这只是一个很小但可能的情况,它会给出异常。
答案 1 :(得分:1)
常见问题可能是
首先:未启用身份验证
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.
第二个:电子邮件无效或密码不够强 例如
Email Password Valid
abc@gmail.com 123Ab! Yes
ab.com 123Ab! invalid email
abc@gmail.com 12345 weak password
第三:不要重复使用同一封电子邮件
要了解更多信息,请捕获异常并进行打印
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();
}
}
});