所以这对我来说是一个棘手的问题,因为这个问题我不清楚。 logcat只是迅速吐出错误的内容,而没有清楚地说明错误之处。
我一直试图做到这一点,因此当用户注册时,会将默认头像添加到他们的帐户,但是由于某些原因,当我向帐户添加默认URI时,注册会失败。该应用程序不会崩溃,并且已创建该帐户,但是该用户未正确添加到我的Firebase数据库中,并且没有向该用户发送身份验证电子邮件。
因此,要创建此默认头像,我已将图像上传到Firebase存储,并已通过此操作将图像的URL转换为URI
public Uri defaultAvatar = Uri.parse("https://firebasestorage.googleapis.com/v0/b/fifty-fifty-1314c.appspot.com/o/defaultavatarmale.png?alt=media&token=def5ee33-6664-4344-bfca-27e4b284df00");
然后,当用户点击注册时,将创建其帐户,并应使用此行将其添加到数据库中
User users = new User(username, email, defaultAvatar, wins, losses, balance, null, 0, false);
只要显示defaultAvatar
的位置为空,帐户注册就可以正常工作,但是每当我将其更改为该URI时,它就会崩溃。这是注册用户的整个方法
firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
sendVerificationEmail();
//start profile activity here
User users = new User(username, email, defaultAvatar, wins, losses, balance, null, 0, false);
FirebaseDatabase.getInstance().getReference("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(users)
.addOnCompleteListener
(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
Toast.makeText(RegisterActivity.this, "A verification link has been sent to your email.", Toast.LENGTH_SHORT).show();
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
} else {
Toast.makeText(RegisterActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
} else {
Toast.makeText(RegisterActivity.this, "Registration not successful, please try again.", Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
给我一个错误的行是:
.setValue(users)
我的logcat在这种情况下应该可以帮助我,但是只要有人尝试注册,我的logcat就是一团糟。我试图过滤其中的内容以查找特定的错误,但是似乎没有任何效果。 Logcat的内容太多,以至于顶部的行立即开始消失,因此我看不到初始错误。如果有人可以帮助我缩小问题,我也将不胜感激!
我会显示我的logcat的内容,但我认为目前它并没有任何用处
2019-01-12 15:30:57.949 3149-3149/com.example.brent.fifty_fifty E/AndroidRuntime: at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@16.0.5:663)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@16.0.5:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@16.0.5:47)
用户类别:
package com.example.brent.fifty_fifty;
导入android.net.Uri;
导入com.google.firebase.storage.StorageReference; 导入com.google.firebase.storage.StorageTask;
public class User {
HomePage hp;
private String email;
private String userName;
private String uid;
private String gameId;
private String currentGameID;
private int position;
private boolean ready, inGame;
private String HorT;
private int wins, losses, score;
private double balance;
private Uri profileImage;
public User() {
}
public User(String userName, int score, String HorT, String uid, String gameId, int position, boolean ready, boolean inGame) {
this.uid = uid;
this.userName = userName;
this.score = score;
this.HorT = HorT;
this.gameId = gameId;
this.ready = ready;
this.position = position;
this.inGame = inGame;
}
public User(String userName, String email, Uri profileImage, int wins, int losses, double balance, String currentGameID, int position, boolean inGame) {
this.userName = userName;
this.email = email;
this.wins = wins;
this.losses = losses;
this.balance = balance;
this.currentGameID = currentGameID;
this.position = position;
this.inGame = inGame;
this.profileImage = profileImage;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getWins() {
return wins;
}
public void setWins(int wins) {
this.wins = wins;
}
public int getLosses() {
return losses;
}
public void setLosses(int losses) {
this.losses = losses;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getHorT() {
return HorT;
}
public void setHorT(String horT) {
HorT = horT;
}
public String getUid() {
uid = hp.uid;
return uid;
}
public String getGameId() {
return gameId;
}
public void setGameId(String gameId) {
this.gameId = gameId;
}
public String getCurrentGameID() {
return currentGameID;
}
public void setCurrentGameID(String currentGameID) {
this.currentGameID = currentGameID;
}
public boolean isReady() {
return ready;
}
public void setReady(boolean ready) {
this.ready = ready;
}
public boolean inGame() {
return inGame;
}
public void inGame(boolean inGame) {
this.inGame = inGame;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public Uri getProfileImage() {
return profileImage;
}
public void setProfileImage(Uri profileImage) {
this.profileImage = profileImage;
}
}
答案 0 :(得分:1)
Realtime Database SDK不能很好地处理Uri对象。它正在尝试对所有其getter方法公开的所有数据执行复杂的序列化。相反,您应该将化身字段的类型指定为字符串,因为这就是您真正要存储的全部。或者,或者为要序列化的所有字段创建一个Map,并确保它们具有要为用户存储的简单数据类型。