在我的堆栈跟踪中发现了这个问题,可能是什么问题?任何人都可以提供帮助。我正在尝试使用recyclerview从firebase检索对象。
我的logcat
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Long to type ysy.spreadsheet.DatabaseView
at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151)
我的结构
public class DatabaseView {
private Integer bodyTemp;
private Integer electroCardiogram;
private Integer perspireRate;
public DatabaseView(){
}
public DatabaseView(Integer bodyTemp, Integer electroCardiogram,Integer perspireRate){
this.bodyTemp= bodyTemp;
this.electroCardiogram= electroCardiogram;
this.perspireRate= perspireRate;
}
public Integer getBodyTemp() {return bodyTemp;}
public void setBodyTemp(Integer bodyTemp) {this.bodyTemp = bodyTemp;}
public Integer getElectroCardiogram() {return electroCardiogram;}
public void setElectroCardiogram(Integer electroCardiogram) {this.electroCardiogram = electroCardiogram;}
public Integer getPerspireRate() {return perspireRate;}
public void setPerspireRate(Integer perspireRate) {this.perspireRate = perspireRate;}
}
我的观看持有人
public static class HealthViewHolder extends RecyclerView.ViewHolder{
public TextView healthBodyTemp;
public TextView healthElectroCardiogram;
public TextView healthPerspireRate;
public HealthViewHolder(View v){
super(v);
healthBodyTemp =(TextView)itemView.findViewById(R.id.bodyTemp);
healthElectroCardiogram= (TextView)itemView.findViewById(R.id.electroCardiogram);
healthPerspireRate=(TextView)itemView.findViewById(R.id.perspireRate);
从firebase阅读
private DatabaseReference mFirebaseDatabaseReference;
private FirebaseRecyclerAdapter<DatabaseView, HealthViewHolder>
mFirebaseAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//intialize RecyclerView
mHealthRecyclerView =
(RecyclerView)findViewById(R.id.healthRecyclerView);
mlinearLayoutManager = new LinearLayoutManager(this);
mlinearLayoutManager.setStackFromEnd(true);
mHealthRecyclerView.setLayoutManager(mlinearLayoutManager);
//Database Initilization
mFirebaseDatabaseReference =
FirebaseDatabase.getInstance().getReference();
mFirebaseAdapter = new FirebaseRecyclerAdapter<DatabaseView,
HealthViewHolder>(
DatabaseView.class,
R.layout.database_view,
HealthViewHolder.class,
mFirebaseDatabaseReference.child(HEALTH))