skip to Main Content

I am working on a college search app and I am unable to solve this error.

Here is the code:

public class searchEngineActivity extends AppCompatActivity {
    public String stateSelected;
    public String courseSelected;
    public RecyclerView searchRecyclerView;
    public WebView webView;
    public FirebaseRecyclerOptions adapter;
    public DatabaseReference databaseReference;
    String queryState, queryCourse;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_engine);

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
        Bundle bundle = getIntent().getExtras();
        stateSelected = bundle.getString("stateSelected");
        courseSelected = bundle.getString("courseSelected");
        Log.e("arguments",stateSelected+courseSelected );
        makeQuery(stateSelected, courseSelected);
        searchRecyclerView = (RecyclerView) findViewById(R.id.searchRecyclerView);
        webView = (WebView) findViewById(R.id.webView);
        searchRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        setAdapter();
        searchRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
    }

    public void makeQuery(String q, String c) {
        queryState = q.replaceAll(" ", "-");
        queryState = queryState.toLowerCase();
        queryCourse = c.toLowerCase();

    }

    public void setAdapter() {
        Query query = FirebaseDatabase.getInstance().getReference().child("searchengines");
        FirebaseRecyclerOptions<searchModelClass> options = new FirebaseRecyclerOptions.Builder<searchModelClass>().setQuery(query, searchModelClass.class).build();
        adapter = new FirebaseRecyclerPagingAdapter<searchModelClass, androidx.recyclerview.widget.RecyclerView.ViewHolder>(options) {

            //@Override
            protected void onBindViewHolder(@NonNull searchRecyclerViewHolder holder, final int position, @NonNull searchModelClass model) {
                holder.setSiteImage(model.getImage());
                holder.setSiteName(model.getName());
                holder.setSiteURL(model.getUrl());
            }

            @Override
            protected void onBindViewHolder(@androidx.annotation.NonNull @NonNull RecyclerView.ViewHolder viewHolder, int position, @androidx.annotation.NonNull @NonNull searchModelClass model) {
            }

            @Override
            protected void onLoadingStateChanged(@androidx.annotation.NonNull @NonNull LoadingState state) {
            }

            @NonNull
            //@Override
            public searchRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.search_recycler_view, parent, false);

                final searchRecyclerViewHolder viewHolder = new searchRecyclerViewHolder(view);
                viewHolder.setOnClickListener(new searchRecyclerViewHolder.ClickListener() {
                    @Override
                    public void onClick(View view, int position) {
                        **databaseReference = adapter.getCurrentList(position);**
                        databaseReference = databaseReference.child(queryCourse);
                        databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {
                                String queryURL = dataSnapshot.getValue(String.class);
                                queryURL = queryURL.replaceAll("state", queryState);
                                webView.loadUrl(queryURL);

                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {
                            }
                        });
                    }
                });
                return viewHolder;
            }
        };
        searchRecyclerView.setAdapter(adapter);
    }

    @Override
    public void onStart() {
        super.onStart();
        FirebaseRecyclerPagingAdapter<Object, RecyclerView.ViewHolder> firebaseRecyclerAdapter = null;
        firebaseRecyclerAdapter.startListening();
    } //UPDATING RECYCLER VIEW REGULARLY FROM THE START OF FRAGMENT
}

Error is:

Cannot resolve method ‘getCurrentList’ in ‘FirebaseRecyclerOptions’:101

I tried to use other library for recycler view in place of firebase ui library, but then I have to change my whole code. What else I can do?

2

Answers


  1. Your adapter object is an object of type FirebaseRecyclerPagingAdapter. When you try to call getCurrentList(position) on such an object, it’s the expected behavior to get the following error:

    Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions':101
    

    Since there is no getCurrentList() method inside your adapter class. Moreover, if such a method existed, as the name says, it would have returned a list and not a DatabaseReference object. So seeing your code, that line of code that produces that error should be removed.

    Login or Signup to reply.
  2. Are you looking for getRef()? That’d be:

    databaseReference = adapter.getRef(position);
    

    I highly recommend keeping the source code for the class you’re using handy in cases like this, as the entire FirebaseAdapter.java file is only 47 lines long and can quickly help you find what does and what doesn’t exist.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search