Я пытаюсь получить данные из моего json для отображения через просмотрщик firebase, но я сталкиваюсь с этой ошибкой:
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.android.heydj.DjProfile
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.6:423)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.6:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.6:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.6:212)
at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:29)
at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:15)
at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:35)
at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:106)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:122)
Мой Json:
"allDeeJays" : {
"-Le5FguoZsnT2lejgAkZ" : "yousucks",
"-Le5IsCPK69NTbgbgUUo" : "ffffggg",
"-Le5J5CmPkddSaK_MgpG" : "ahhhaahhaahha"
}
Мой класс DjProfile определяется следующим образом:
public class DjProfile
{
String djName;
String googleUserName;
public DjProfile(String djName, String googleUserName)
{
this.djName = djName;
this.googleUserName = googleUserName;
}
public DjProfile(){}
public void setdjName(String djName)
{
this.djName = djName;
}
public String getdjName()
{
return djName;
}
}
Мой обзор переработчика пожарной базы выглядит следующим образом:
query = mProfileDatabase.child("allDeeJays")
.orderByValue()
.startAt(t.getText().toString()).endAt(t.getText().toString() + "\uf8ff");
FirebaseRecyclerOptions<DjProfile> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<DjProfile>()
.setQuery(query, DjProfile.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<DjProfile, ResultsViewHolder>(firebaseRecyclerOptions)
{
@NonNull
@Override
public ResultsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.searchitem_list, viewGroup, false);
return new ResultsViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull ResultsViewHolder holder, final int position, @NonNull final DjProfile model) {
holder.setDjProfile(model);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplication(), AddSongRequest.class);
i.putExtra("DjName", model.getdjName());
startActivity(i);
}
});
}
};
firebaseRecyclerAdapter.startListening();
Класс ViewHolder для рециркулятора Firebase:
public static class ResultsViewHolder extends RecyclerView.ViewHolder
{
private TextView djNameView;
public ResultsViewHolder(View itemView)
{
super(itemView);
djNameView = itemView.findViewById(R.id.result_dj);
}
void setDjProfile(DjProfile profile)
{
String djName = profile.getdjName();
profile.setdjName(djName);
}
}
Любая помощь приветствуется:)
EDIT
Мой JSON теперь отформатирован как:
"allDeeJays" : {
"-LeNGZKDoIcVOLUokvrP" : {
"djName" : "ahhahaha"
},
"-LeNGb2sy9qG_U0zA1xS" : {
"djName" : "newdj"
}
}
И теперь я не могу отобразить значения имени в представлении реселлера, используя следующее:
query = mProfileDatabase.child("allDeeJays")
.orderByValue()
.startAt(t.getText().toString()).endAt(t.getText().toString() + "\uf8ff");