How to fix this error?

error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter cannot be applied to given types; required: FirebaseRecyclerOptions found: Class,int,Class,DatabaseReference reason: actual and formal argument lists differ in length where T,VH are type-variables: T extends Object declared in class FirebaseRecyclerAdapter VH extends ViewHolder declared in class FirebaseRecyclerAdapter

mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage,
            MessageViewHolder>(
            FriendlyMessage.class,
            R.layout.activity_my_message,
            MessageViewHolder.class,
            mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {

        @Override
        protected void populateViewHolder(MessageViewHolder viewHolder,
                                          FriendlyMessage friendlyMessage, int position) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            viewHolder.messageTextView.setText(friendlyMessage.getText());
            viewHolder.messengerTextView.setText(friendlyMessage.getName());
            if (friendlyMessage.getPhotoUrl() == null) {
                viewHolder.messengerImageView
                        .setImageDrawable(ContextCompat
                                .getDrawable(Loand.this,
                                        R.drawable.ic_account_circle_black_36dp));
            } else {
                Glide.with(Loand.this)
                        .load(friendlyMessage.getPhotoUrl())
                        .into(viewHolder.messengerImageView);
            }
        }
    };

    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition =
                    mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // If the recycler view is initially being loaded or the
            // user is at the bottom of the list, scroll to the bottom
            // of the list to show the newly added message.
            if (lastVisiblePosition == -1 ||
                    (positionStart >= (friendlyMessageCount - 1) &&
                            lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });

    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);

1 Answers

0
Alex Mamo On Best Solutions

You are getting the following error:

error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter cannot be applied to given types; required: FirebaseRecyclerOptions found: Class,int,Class,DatabaseReference reason: actual and formal argument lists differ in length where T,VH are type-variables: T extends Object declared in class FirebaseRecyclerAdapter VH extends ViewHolder declared in class FirebaseRecyclerAdapter

Because you have added one of the latest versions of the Firebase-UI library dependency in your build.gradle file. To be able to create a new object of the FirebaseRecyclerAdapter class, a FirebaseRecyclerOptions object is required. What you are doing, is passing wrong elements to the constructor. That way of creating the adapter was available in the older versions. Now, to create a new object, pass FirebaseRecyclerOptions object, as explained in my answer from the following post: