Search code examples
androidfirebaseandroid-recyclerviewadapterfirebaseui

FirebaseRecyclerAdapter model returns null


I have a FirebaseRecyclerAdapter and its model is returning null. When I access the model object which is of POJO class, it returns only null. I have checked the whole code with firebase-UI and with firebase-quickstart examples.

FirebaseRecyclerAdapter

mAdapter = new FirebaseRecyclerAdapter<EventDetails, EventViewHolder>(EventDetails.class,R.layout.event_viewholder,EventViewHolder.class,myQuery) {

            @Override

            protected void populateViewHolder(final EventViewHolder viewHolder,final EventDetails model,final int position) {

                final DatabaseReference eventRef = getRef(position);


                final String postKey = eventRef.getKey();

                viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

                    @Override

                    public void onClick(View v) {

                        Message.ts(getActivity(),"Clicked on key" + postKey);

// Intent intent = new Intent(getActivity(), PostDetailActivity.class);

// intent.putExtra("", postKey);

// startActivity(intent);

                    }

                });


                Message.ts(getActivity(),"safdfdf"+model.getEventName());


                viewHolder.Name.setText(eventRef.child("eventName").child());

                viewHolder.Desc.setText(model.getEventDesc());

                if (model.getCoordinates()!=null){

                    viewHolder.Location.setVisibility(View.VISIBLE);

                    String[] ltlng = model.getCoordinates().split(",");

                    String url = "http://maps.google.com/maps/api/staticmap?center=" + ltlng[0] + "," + ltlng[1] + "&zoom=15&size=400x200&sensor=false";

                    viewHolder.Map.setImageUrl(url,mImageLoader);

                }


            }

        };

        mRecyclerView.setAdapter(mAdapter);

Pojo class

public class EventDetails {

    private String EventName, EventDesc;

    private int limit = -1;

    private String Coordinates;


    public EventDetails(){}//Empty constructor for Firebase


    public EventDetails(String eventName, String eventDesc) {

        this.EventName = eventName;

        this.EventDesc = eventDesc;

    }


    public int getLimit() {

        return limit;

    }


    public void setLimit(int limit) {

        this.limit = limit;

    }


    public String getCoordinates() {

        return Coordinates;

    }


    public void setCoordinates(String coordinates) {

        Coordinates = coordinates;

    }


    public String getEventName() {

        return EventName;

    }


    public String getEventDesc() {

        return EventDesc;

    }

}

Viewholder

public class EventViewHolder extends RecyclerView.ViewHolder {


    public TextView Name, Desc, Date;

    public NetworkImageView Map;

    public LinearLayout Location;


    public EventViewHolder(View itemView) {

        super(itemView);

        Name = (TextView) itemView.findViewById(R.id.eventNameDisp);

        Desc = (TextView) itemView.findViewById(R.id.eventDescDisp);

        Date = (TextView) itemView.findViewById(R.id.dateDisp);

        Map = (NetworkImageView) itemView.findViewById(R.id.mapNIView);

        Location = (LinearLayout) itemView.findViewById(R.id.location);

    }

}

Firebase-UI version :1.01(latest) Firebase/Play Services version: 10.0.1


Solution

  • The problem was solved by adding proper constructors and getters and setter method in the POJO class.

        public class EventDetails {
    
        private String EventName, EventDesc;
    
        private int limit = -1;
    
        private String Coordinates;
    
        private String Date;
    
        private String date;
    
    
        public EventDetails() {
    
        }//Empty constructor for Firebase
    
    
        public EventDetails(String eventName, String eventDesc, String Date) {
    
            this.EventName = eventName;
    
            this.EventDesc = eventDesc;
    
            this.Date = Date;
    
        }
    
    
        public EventDetails(String EventName,String EventDesc,int limit,String Coordinates,String Date){
    
            this.EventName = EventName;
    
            this.EventDesc = EventDesc;
    
            this.limit = limit;
    
            this.Coordinates = Coordinates;
    
            this.Date = Date;
    
        }
    
    
        public int getLimit() {
    
            return limit;
    
        }
    
    
        public void setLimit(int limit) {
    
            this.limit = limit;
    
        }
    
    
        public String getCoordinates() {
    
            return Coordinates;
    
        }
    
    
        public void setCoordinates(String coordinates) {
    
            Coordinates = coordinates;
    
        }
    
    
    
        public String getEventName() {
    
            return EventName;
    
        }
    
    
        public void setEventName(String eventName) {
    
            EventName = eventName;
    
        }
    
    
        public String getEventDesc() {
    
            return EventDesc;
    
        }
    
    
        public void setEventDesc(String eventDesc) {
    
            EventDesc = eventDesc;
    
        }
    
    
        public String getDate() {
    
            return date;
    
        }
    
    }
    

    And thank you nobody for helping!!