1
So, guys, it’s kind of a beat-up question I know, but I couldn’t find a solution to my code here. I need to get the information that’s inside node 5883, but apparently it populates my class with the information that’s on the outside and ends up making the mistake W/ClassMapper: No setter/field for 5883 found on class com.mycomics.rest.model.ComicVineIssueModel
and I can’t make the comparison I need.
Firebase:
Comicvinemodel:
public class ComicVineModel{
private Long id;
private String name;
private String api_detail_url;
public ComicVineModel() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getApi_detail_url() {
return api_detail_url;
}
public void setApi_detail_url(String api_detail_url) {
this.api_detail_url = api_detail_url;
}
}
Comicvineissuemodel
public class ComicVineIssueModel extends ComicVineModel{
private ComicVineModel volume;
private Integer issue_number;
private String store_date;
private String cover_date;
private ComicVineImageModel image;
private String description;
public ComicVineIssueModel() {
}
public Integer getIssue_number() {
return issue_number;
}
public void setIssue_number(Integer issue_number) {
this.issue_number = issue_number;
}
@Exclude
public ComicVineModel getVolume() {
return volume;
}
public void setVolume(ComicVineModel volume) {
this.volume = volume;
}
@Exclude
public String getStore_date() {
return store_date;
}
public void setStore_date(String store_date) {
this.store_date = store_date;
}
@Exclude
public ComicVineImageModel getImage() {
return image;
}
public void setImage(ComicVineImageModel image) {
this.image = image;
}
@Exclude
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Exclude
public String getCover_date() {
return cover_date;
}
public void setCover_date(String cover_date) {
this.cover_date = cover_date;
}
}
Issueadapter (where I am saving and searching the data)
public class IssueAdapter extends RecyclerView.Adapter<IssueAdapter.MyViewHolder> {
private List<ComicVineIssueModel> issue;
private Context context;
private boolean isExpand;
private String textoFormatado = "";
private FirebaseAuth autenticacao;
private DatabaseReference firebase;
private ChildEventListener childListenerEdicao;
private ComicVineIssueModel issueModel = new ComicVineIssueModel();
private ArrayList<ComicVineIssueModel> listIssue = new ArrayList();
private String volume;
private String idEdicao;
public IssueAdapter(List<ComicVineIssueModel> issue, Context context, String volume) {
this.issue = issue;
this.context = context;
this.volume = volume;
setHasStableIds(true);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemLista = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_issue, parent, false);
firebase = ConfigFirebase.getFirebase();
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
issueModel = issue.get(position);
/*Código retirado para uma melhor visualização de onde pode estar o problema*/
idEdicao = issueModel.getId().toString();
holder.check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(holder.check.getTag().equals("isChecked")){
holder.check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.uncheck));
firebase.child(usuario()).child(volume).child(issue.get(position).getId().toString()).removeValue();
holder.check.setTag("uncheck");
Toast.makeText(context, issue.get(position).getName() + " deletado com sucesso!", Toast.LENGTH_LONG).show();
}else {
holder.check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.check));
holder.check.setTag("isChecked");
issueModel.setIssue_number(issue.get(position).getIssue_number());
issueModel.setName(issue.get(position).getName());
issueModel.setId(issue.get(position).getId());
//salva a revista no Firebase no formato de: usuario - id da revista - id da edição - dados da revista
DatabaseReference firebaseSalvaRevista = FirebaseDatabase.getInstance().getReference(usuario());
firebaseSalvaRevista.child(volume).child(issue.get(position).getId().toString()).setValue(issueModel);
Toast.makeText(context, issue.get(position).getName() + " está nos favoritos!", Toast.LENGTH_LONG).show();
}
}
});
firebase.child(usuario()).child(volume).child(idEdicao);
recuperarDados(idEdicao, holder.check);
firebase.addChildEventListener(childListenerEdicao);
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return issue.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
private TextView ano;
private TextView titulo;
private TextView edicao;
private ImageView capa;
private ImageView check;
private TextView informacoes;
private ImageView seta;
public MyViewHolder(View itemView) {
super(itemView);
ano = itemView.findViewById(R.id.idAnoEdicao);
titulo = itemView.findViewById(R.id.idTitulo);
capa = itemView.findViewById(R.id.idImagemEdicao);
edicao = itemView.findViewById(R.id.idEdicao);
informacoes = itemView.findViewById(R.id.idInformacoes);
seta = itemView.findViewById(R.id.idSetaInformacoes);
check = itemView.findViewById(R.id.idUncheck);
}
}
public String usuario(){
autenticacao = ConfigFirebase.getFirebaseAutenticacao();
String usuario = autenticacao.getCurrentUser().getEmail().toString();
usuario = Base64Custom.codificarBase64(usuario);
return usuario;
}
public void recuperarDados(final String id, final ImageView check){
childListenerEdicao = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
listIssue.clear();
for(DataSnapshot dados : dataSnapshot.getChildren()) {
issueModel = dados.getValue(ComicVineIssueModel.class);
listIssue.add(issueModel);
if(issueModel.getId().toString().equals(id)){
check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.check));
check.setTag("isChecked");
}
}
IssueAdapter.this.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
}
}
Hello, I think you have a problem in the way you save the data, but to solve your problem, you can pick up the values with a Map...
– Eduardo Ceolin
Dude, I’m kind of new at this and I don’t know how to use Map, would you give me an example? Thanks!
– Arthurfmg
I’ve been searching the net and managed to solve my problem using Map. Thanks for the tip!
– Arthurfmg