1
I’m having problems with my TCC, I’m not getting the data from Firebase and display them in a listview, it presents error, I’m using the ValueEventListener to try to get the data... to listview this in a fragment. Does anyone know how to solve this problem ???
ERROR:
FATAL EXCEPTION: main Process: Matheus.example.com.topaziovilleapp, PID: 13075 com.google.firebase.database.Databaseexception: Can’t Convert Object of type java.lang.String to type Matheus.example.com.topaziovilleapp.Modelo.Noticias 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 Matheus.example.com.topaziovilleapp.Fragments.fragmentNoticias$1.onDataChange(fragmentNoticias.java:61) at com.google.android.gms.Internal.zzbmz.zza(Unknown Source)
Fragment
public class fragmentNoticias extends Fragment {
private ListView listView;
private ArrayAdapter adapter;
private ArrayList<String> noticias;
private DatabaseReference databaseReference;
private FirebaseAuth autenticacao;
private String usuariologado;
public fragmentNoticias() {
    // Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_noticias, container, false);
    noticias = new ArrayList<>();
    listView = (ListView) view.findViewById(R.id.lv_noticias);
    adapter = new ArrayAdapter(
            getActivity(),
            android.R.layout.simple_list_item_1,
            noticias
    );
    listView.setAdapter(adapter);
    autenticacao = FirebaseConfig.getAutenticacao();
    databaseReference = FirebaseConfig.getFirebase().child("Noticias");
    databaseReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            noticias.clear();
            for (DataSnapshot dados: dataSnapshot.getChildren()){
                Noticias noticia = dados.getValue(Noticias.class);
                noticias.add(noticia.getTitulo());
            }
            adapter.notifyDataSetChanged();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return view;
}
}
Model Class
public class Noticias {
private String titulo;
private String noticia;
private String data;
private String imagem;
public Noticias() {
}
public String getTitulo() {
    return titulo;
}
public void setTitulo(String titulo) {
    this.titulo = titulo;
}
public String getNoticia() {
    return noticia;
}
public void setNoticia(String noticia) {
    this.noticia = noticia;
}
public String getData() {
    return data;
}
public void setData(String data) {
    this.data = data;
}
public String getImagem() {
    return imagem;
}
public void setImagem(String imagem) {
    this.imagem = imagem;
}
