-1
I’m creating a Java/Android app where your job is basically to display a list for the user about what items we still have available in stock.
To make this list I used a Recycler View, data (stock items) are manually added by me on Firebase, this in turn mirrors the data as a list (recyclerView) in my app.
So far everything has gone very well...
However, when running the app the following message appears in my Logcat:
W/ClassMapper: No setter/field for dT (difiteria e tétano) found on class com.imagine.edielsonpereira.cs_ivacinasstock.activity.modelagem.Vacina
I also realized that my methods Setters, in my modeling class, are not being used because they are faded, I assume the problem is there.
Follow the warning (I wouldn’t say it’s a bug) in Logcat:
Configuration of Realtime Database that communicates with my app:
Follows the main class configuration:
Class Configuracaofirebase
package com.imagine.edielsonpereira.cs_ivacinasstock.activity.config;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class ConfiguracaoFirebase {
private static DatabaseReference firebase;
//Retorna Instancia do Firebase
public static DatabaseReference getFirebaseDatabase(){
if(firebase == null){
firebase = FirebaseDatabase.getInstance().getReference();
}
return firebase;
}
}
Adapter:
package com.imagine.edielsonpereira.cs_ivacinasstock.activity.adapter;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.imagine.edielsonpereira.cs_ivacinasstock.R;
import com.imagine.edielsonpereira.cs_ivacinasstock.activity.modelagem.Vacina;
import java.util.List;
public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder> {
private List<Vacina> listaVacinas;
Context context;
public Adapter(List<Vacina> listaVacinas, Context context) {
this.listaVacinas = listaVacinas;
this.context = context;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//Converte o objeto do tipo XML em uma View.
View itemLista = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_lista, viewGroup, false);
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
Vacina vacina = listaVacinas.get(i);
myViewHolder.vacina.setText(vacina.getTipoVacina());
myViewHolder.doses.setText(vacina.getDoses());
//Muda cor do texto das vacinas com saldo 0 para vermelho
if(vacina.getDoses() == "0 doses" ){
myViewHolder.doses.setTextColor(context.getResources().getColor(R.color.colorAccent));
}
}
@Override
public int getItemCount() {
return listaVacinas.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
ImageView imagem;
TextView vacina;
TextView doses;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
imagem = itemView.findViewById(R.id.imageSeringa);
vacina = itemView.findViewById(R.id.textVacina);
doses = itemView.findViewById(R.id.textDoses);
}
}
}
Thanks in advance for your willingness to help me...
setTipoVacina... setDoses... are faded, I still don’t understand why.
– Edielson Pereira
This happens because you do not use these methods. Already the log indicates that, probably, the properties names in the
Firebase
are different from the names ofsetters
andgetters
– Ivan Silva
That’s the question Ivan, how are they not being used? These were automatically generated by Android Studio for such function.
– Edielson Pereira
You need to call them:
vacina.getVacina() e vacina.getDose()
. But that’s not a mistake.– Ivan Silva
It still doesn’t work here, the Recyclerview does not mirror my data I added to Firebase.
– Edielson Pereira
Edit the question by adding the code from
adapter
, ofactivity
and ofFirebase Database
(do not forget to shred some sensitive information). Only with this question information will not be possible to solve your problem.– Ivan Silva
Written @Ivansilva, I hope it’s a little clearer.
– Edielson Pereira