gpt4 book ai didi

java - 单击注册按钮时应用程序崩溃(使用 firebase )

转载 作者:行者123 更新时间:2023-12-03 11:20:23 25 4
gpt4 key购买 nike

每当我单击登录页面应用程序中的注册按钮时,它就会崩溃,并且不会移动到下一个 Activity 。我已经被困在这个问题上一天了,似乎在任何地方都找不到解决方案。

这是我为注册按钮方法编写的代码。
( emailTextpasswordText 是 TextInputLayout)

 public void signup(View view){
if(!validatePassword()|!validateEmail()){
return;
}
else{
ref = FirebaseDatabase.getInstance().getReference();
ref.child("users").child(emailText.getEditText().getText().toString()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {

emailText.setError("Username or Email already exists, pick another!");
} else {

mAuth.createUserWithEmailAndPassword(emailText.getEditText().getText().toString(), passwordText.getEditText().getText().toString())
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {

FirebaseUser user = mAuth.getCurrentUser();

startActivity(intent);
} else {


Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();

}


}
});
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

}

}

Logcat 在第 7 行显示错误,即 ref.child(... line.
我已经尝试过第 7 行的替代方法,例如: ref.child("users").child("username").addLi....但是没有任何进展。

这是日志
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@1a7dad29 rejected from com.google.firebase.database.core.utilities.DefaultRunLoop$1@28fb68ae[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:298)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:503)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:592)
at com.google.firebase.database.core.utilities.DefaultRunLoop.scheduleNow(com.google.firebase:firebase-database@@16.0.6:105)
at com.google.firebase.database.core.Repo.scheduleNow(com.google.firebase:firebase-database@@16.0.6:276)
at com.google.firebase.database.Query.addEventRegistration(com.google.firebase:firebase-database@@16.0.6:233)
at com.google.firebase.database.Query.addListenerForSingleValueEvent(com.google.firebase:firebase-database@@16.0.6:175)
at com.example.admin.instagramclone.MainActivity.signup(MainActivity.java:66)
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384) 
at android.view.View.performClick(View.java:4791) 
at android.view.View$PerformClick.run(View.java:19903) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5296) 
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:912) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 

最佳答案

就我而言,我更新了最新版本的 firebase 实时数据库,问题已解决

implementation 'com.google.firebase:firebase-database:19.5.1'

关于java - 单击注册按钮时应用程序崩溃(使用 firebase ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56644924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com