yanish appadoo
yanish appadoo

Reputation: 57

return null value when reading from firebase

attributes of the class supplierClass returns null. Datasnapshot assigns correctly to the attributes. However the list does not provide the right values. only material name works

  1. screenshot 1- snapshot value enter image description here
  2. screenshot 2- output screen enter image description here

Code

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.fragment_suppliers,container,false);
        recyclerView=view.findViewById(R.id.suppliersList);
        databaseReference= FirebaseDatabase.getInstance().getReference("suppliers");
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        list= new ArrayList<>();
        myAdapter=new recyclerAdapter(getActivity(),list);
        recyclerView.setAdapter(myAdapter);
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                for(DataSnapshot dataSnapshot:snapshot.getChildren())
                {
                    supplierClass sc=dataSnapshot.getValue(supplierClass.class);
                    list.add(sc);
                }
                myAdapter.notifyDataSetChanged();

            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {

            }
        });


        return view;

Upvotes: 0

Views: 328

Answers (1)

yanish appadoo
yanish appadoo

Reputation: 57

attributes names should be same as on firebase DB

String sName, equipmentName, materialName; 
        public String getsName() {
            return sName;
        }
    
        public String getEquipmentName() {
            return equipmentName;
        }
    
        public String getMaterialName() {
            return materialName;
        }

Upvotes: 1

Related Questions