gpt4 book ai didi

java - Firebase:类 java.util.List 具有通用类型参数

转载 作者:行者123 更新时间:2023-11-29 02:35:54 25 4
gpt4 key购买 nike

我正在为我的 android 应用程序使用 firebase,并将我自己的用户对象存储在数据库中。但是,每当我尝试从数据库中的信息创建用户对象时,我都会收到以下错误:

com.google.firebase.database.DatabaseException: Class java.util.List has generic type parameters, please use GenericTypeIndicator instead
at com.google.android.gms.internal.zzear.zzb(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.android.gms.internal.zzear.zzb(Unknown Source)
at com.google.android.gms.internal.zzeas.zze(Unknown Source)
at com.google.android.gms.internal.zzear.zzb(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.android.gms.internal.zzear.zzb(Unknown Source)
at com.google.android.gms.internal.zzeas.zze(Unknown Source)
at com.google.android.gms.internal.zzear.zzb(Unknown Source)
at com.google.android.gms.internal.zzear.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at christophershae.stats.CreateRoster$1.onDataChange(CreateRoster.java:88)
at com.google.android.gms.internal.zzduz.zza(Unknown Source)
at com.google.android.gms.internal.zzdwu.zzbvb(Unknown Source)
at com.google.android.gms.internal.zzdxa.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这是我的用户类:

public class User implements Serializable {
public String email;

public Map<String, List<BasketballPlayer>> userRosters = new
HashMap<String, List<BasketballPlayer>>();


public User(){

}

public User(String email){
this.email = email;
}

}

这是我尝试创建新对象的代码:

@Override
public void onDataChange(DataSnapshot dataSnapshot) {
user = dataSnapshot.child(userId).getValue(User.class);

}

最佳答案

改变这个:-

user = dataSnapshot.child(userId).getValue(User.class);

进入这个:-

List<BasketBallPlayer> retrievedata=dataSnapshot.child(userId).getValue(userRosters);

关于java - Firebase:类 java.util.List 具有通用类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47104132/

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