在本主题中,我已经看了很多主题,但是我无法在自己的代码中修改代码。因为显然有一个我看不到的错误。而且我得到了错误。
EpisodeModel.class
公共类EpisodeModel {
private String episode;
public EpisodeModel(String episode) {
this.episode = episode;
}
public EpisodeModel()
{
}
public String getEpisode() {
return episode;
}
public void setEpisode(String episode) {
this.episode = episode;
}
@Override
public String toString() {
return "EpisodeModel{" +
"episode='" + episode + '\'' +
'}';
}
}
MyFragment.class
public void check() {
ref.child("Users").child(user.getUid()).child("Watched").child(seriesTitle).child("Season").child(seasonGet)
.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
EpisodeModel episodeModel = dataSnapshot.getValue(EpisodeModel.class);
Log.i("child",episodeModel.toString());
Log.i("test","test2");
String st = dataSnapshot.getKey();
int no = Integer.parseInt(st);
if(!deneme.contains(no))
{
deneme.add(no);
}
checkModelTestAdapter.notifyDataSetChanged();
}
...onChildChanged..onChildRemoved..onChildMoved..onCancelled..}};
Logcat
Process: com.example.forev.seriesboiler, PID: 6959
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Boolean to type com.example.forev.seriesboiler.Models.EpisodeModel
at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.example.forev.seriesboiler.Fragments.SeriesDetailsFragment$1.onChildAdded(SeriesDetailsFragment.java:88)
at com.google.android.gms.internal.firebase_database.zzbt.zza(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source)
at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
最佳答案
EpisodeModel EpisodeModel = dataSnapshot.getValue(EpisodeModel.class);
在此行中,您得到错误消息,表明布尔对象无法转换为EpisodeModel。如果您已将该子项的值设置为true或false(不带双引号),则可能会出现。再次看到它,并尝试在要设置为子值的“ true”或“ false”周围添加双引号。