Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用户注册与URI问题_Java_Android_Firebase Realtime Database_Firebase Authentication - Fatal编程技术网

Java 用户注册与URI问题

Java 用户注册与URI问题,java,android,firebase-realtime-database,firebase-authentication,Java,Android,Firebase Realtime Database,Firebase Authentication,所以这对我来说是一个很难问的问题,因为我不清楚这个问题。logcat只是快速地吐出一行又一行的错误,没有清楚地解释什么是错误的 我一直试图做到这一点,当用户注册时,默认的化身被添加到他们的帐户中,但由于某种原因,当我向帐户添加默认URI时,注册失败。应用程序不会崩溃,并且已创建帐户,但用户未正确添加到我的Firebase数据库,并且未向用户发送身份验证电子邮件 因此,为了创建这个默认的化身,我将一个图像上传到我的Firebase存储中,并通过这样做将图像的URL转换为URI public Uri

所以这对我来说是一个很难问的问题,因为我不清楚这个问题。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");
然后,当用户点击register时,将创建他们的帐户,并使用此行将其添加到数据库中

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();
            }
        }
    });
在这种情况下,我的日志本应帮助我,但每当有人试图注册时,它就乱成一团。我试图过滤其中的内容,以找到特定的错误,但似乎没有任何效果。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;
}

}

实时数据库SDK不能很好地处理Uri对象。它试图对其所有getter方法公开的所有数据执行复杂的序列化。相反,您应该将化身字段的类型指定为一个字符串,因为这就是您真正想要存储的所有内容。要么这样做,要么创建所有要序列化的字段的映射,并确保它们具有要为用户存储的简单类型的数据。

我认为尝试了解日志中的内容是值得的,因为如果没有错误消息,我们只能猜测。@DougStevenson我粘贴了日志的剪贴画,但是还有7000多行基本上只是snippit的重复。什么是你的用户类?@DougStevenson将其添加到postSo的底部。如果我将URI类型更改为字符串,并将URL存储为字符串,那么要将化身显示为图像,我是否应该将其转换回图像显示的URI?这样行吗?是的,如果你需要一个Uri,就转换它。
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;
}

}