0

I am trying to use android studio to get firebase data and display it on the screen. I am trying to display anything that is in the database related to it to a RecyclerView. But the data does not return and nothing displays (no error statement). Any ideas why?

private void firebaseLotSearch() {

        Toast.makeText(BuyingParking.this,"Started Search",Toast.LENGTH_LONG).show();
        Query query = mUserDatabase.startAt(searchText).endAt(searchText+"\uf8ff");
                FirebaseRecyclerOptions<Lot_Location> options =
                new FirebaseRecyclerOptions.Builder<Lot_Location>()
                        .setQuery(query, Lot_Location.class)
                        .build();

        //   Lot_Location.class,R.layout.list_layout,LotViewHolder.class,mUserDatabase
        FirebaseRecyclerAdapter<Lot_Location,LotViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Lot_Location, LotViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull LotViewHolder holder, int position, @NonNull Lot_Location model) {

                holder.setDetails(model.getLocation(),model.getAdmin(),model.getPrice());

            }
            @NonNull
            @Override
            public LotViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
                return null;
            }
        };
        searchParking.setAdapter(firebaseRecyclerAdapter);
    }

    public class LotViewHolder extends RecyclerView.ViewHolder{
        public LotViewHolder(@NonNull View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setDetails(String location,String admin,String price)
        {
            TextView m_location = (TextView)mView.findViewById(R.id.Lot);
            TextView m_admin = (TextView)mView.findViewById(R.id.Admin);
            TextView m_price = (TextView)mView.findViewById(R.id.price);

            m_location.setText(location);
            m_admin.setText(admin);
            m_price.setText(price);
        }

    }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
John C
  • 517
  • 2
  • 6
  • 16
  • You can set a [breakpoint](https://developer.android.com/studio/debug) and investigate what happens – Erik Mar 21 '19 at 18:59
  • You seem to not be calling `startListening()` anywhere in your c ode, which is required for FirebaseUI to start observing the database. Please check the duplicate. – Alex Mamo Mar 22 '19 at 09:43

1 Answers1

0

onCreateViewHolder is returning null. You need to return an object of LotViewHolder class.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View rootView = mInflater.inflate(R.layout.your_item_view, parent, false);
    ViewHolder holder = new ViewHolder(rootView);
    return holder;
}
Anurag Meena
  • 166
  • 2
  • 4