gpt4 book ai didi

android - 无法在 Firebase 中保存新数据

转载 作者:行者123 更新时间:2023-12-05 00:21:50 25 4
gpt4 key购买 nike

我正在尝试将新数据保存在节点 Visitors 下的 firebase 中.我已经在那个节点上设置了一些规则。

"Visitor":{
"$userId":{
".write": "auth != null && $userId === auth.uid",
".read": " auth.uid != null"
}
},

在我的应用程序中
FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance();
FirebaseUser mFirebaseUser = mFirebaseAuth.getCurrentUser();
FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();

if(mFirebaseUser == null){

}else{
String mUserId = mFirebaseUser.getUid();
DatabaseReference vRef = mDatabase.getReference(MyFirebaseConstants.DATABASE_Visitor);
DatabaseReference newVisitorRef = vRef.child(mUserId).push();
String visitorKey = newVisitorRef.getKey();

Visitor visitor = new Visitor()//POJO
// other few setters

visitor.setId(visitorKey);
newVisitorRef.setValue(property);

我的访问者 pojo 扩展了 RealmObject 并实现 Parcelable

但是我收到以下错误
 java.lang.StackOverflowError
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.google.android.gms.internal.zzamy$zza.zzci(Unknown Source)
at com.google.android.gms.internal.zzamy.zzca(Unknown Source)
at com.google.android.gms.internal.zz
//and many more like this

我的访客 pojo
      public class Visitor extends RealmObject implements Parcelable{

@PrimaryKey
private long timeStamp;
private String visitorId;
private String phoneNumber="";
private String profileUri="";

public Visitor(){

}

protected Visitor(Parcel in) {
timeStamp = in.readLong();
visitorId = in.readString();
phoneNumber = in.readString();
profileUri = in.readString();
}

public static final Creator<Visitor> CREATOR = new Creator<Visitor>() {
@Override
public Visitor createFromParcel(Parcel in) {
return new Visitor(in);
}

@Override
public Visitor[] newArray(int size) {
return new Visitor[size];
}
};

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(timeStamp);
dest.writeString(visitorId);
dest.writeString(phoneNumber);
dest.writeString(profileUri);
}
public void setTimeStamp(long timeStamp){
this.timeStamp = timeStamp;
}

public long getTimeStamp(){
return this.timeStamp;
}

public void setVisitorId(String visitorId){
this.visitorId = visitorId;
}

public void setPhoneNumber(String phoneNumber){
this.phoneNumber = phoneNumber;
}

public Uri getProfileUri() {
return Uri.parse(profileUri);
}
public void setProfileUri(Uri profileUri) {
this.profileUri = profileUri.toString();
}

}

最佳答案

我知道问题出在我的 pojo 中

public Uri getProfileUri() {
return Uri.parse(profileUri);
}

public void setProfileUri(Uri profileUri) {
this.profileUri = profileUri.toString();
}

Realm 支持 Uri 类型的 getter和类型为 Uri 的二传手作为参数但 firebase 数据库 .

所以在我的pojo中,我改为
public String getProfileUri() {
return profileUri;
}
public void setProfileUri(String profileUri) {
this.profileUri = profileUri;
}

关于android - 无法在 Firebase 中保存新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40317713/

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