The problem is in the FirebaseRecyclerAdapter . It produces the following error:

Error: (73, 86) error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter cannot be applied to given types; The following are the types of variables that you can use for the FirebaseRecyclerAdapter and the FirebaseRecyclerOptions found

I already read the documentation and changed the code. Nothing happens. I ask for help in solving the problem. I can’t make it new.

 private void loadData() { Query query = fNotesDatabase.orderByValue(); FirebaseRecyclerAdapter<NoteModel, NoteViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>( NoteModel.class, R.layout.activity_notes, NoteViewHolder.class, query ) { @Override protected void populateViewHolder(final NoteViewHolder viewHolder, NoteModel model, int position) { final String noteId = getRef(position).getKey(); fNotesDatabase.child(noteId).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.hasChild("title") && dataSnapshot.hasChild("timestamp")) { String title = dataSnapshot.child("title").getValue().toString(); String timestamp = dataSnapshot.child("timestamp").getValue().toString(); viewHolder.setNoteTitle(title); //viewHolder.setNoteTime(timestamp); GetTimeAgo getTimeAgo = new GetTimeAgo(); viewHolder.setNoteTime(getTimeAgo.getTimeAgo(Long.parseLong(timestamp), getApplicationContext())); viewHolder.noteCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(NotesMine.this, NewNoteActivity.class); intent.putExtra("noteId", noteId); startActivity(intent); } }); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } 

Here are the changes in the code.

 public class NotesMine extends AppCompatActivity { private FirebaseAuth fAuth; private RecyclerView mNotesList; private GridLayoutManager gridLayoutManager; private DatabaseReference fNotesDatabase; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); mNotesList = (RecyclerView) findViewById(R.id.notes_list); gridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false); mNotesList.setHasFixedSize(true); mNotesList.setLayoutManager(gridLayoutManager); // gridLayoutManager.setReverseLayout(true); //gridLayoutManager.setStackFromEnd(true); mNotesList.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true)); fAuth = FirebaseAuth.getInstance(); if (fAuth.getCurrentUser() != null) { fNotesDatabase = FirebaseDatabase.getInstance().getReference().child("Notes").child(fAuth.getCurrentUser().getUid()); } } @Override public void onStart() { super.onStart(); } private Query query = fNotesDatabase; FirebaseRecyclerOptions<NoteModel> options = new FirebaseRecyclerOptions.Builder<NoteModel>() .setQuery(query, NoteModel.class) .build(); FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(options) { @Override public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.activity_notes, parent, false); return new NoteViewHolder(view); } @Override protected void onBindViewHolder(final NoteViewHolder holder, int position, NoteModel model) { final String noteId = getRef(position).getKey(); fNotesDatabase.child(noteId).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.hasChild("title") && dataSnapshot.hasChild("timestamp")) { String title = dataSnapshot.child("title").getValue().toString(); String timestamp = dataSnapshot.child("timestamp").getValue().toString(); holder.setNoteTitle(title); holder.setNoteTime(timestamp); GetTimeAgo getTimeAgo = new GetTimeAgo(); holder.setNoteTime(getTimeAgo.getTimeAgo(Long.parseLong(timestamp), getApplicationContext())); holder.noteCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(NotesMine.this, NewNoteActivity.class); intent.putExtra("noteId", noteId); startActivity(intent); } }); } } @Override public void onCancelled(DatabaseError databaseError) { } }); mNotesList.setAdapter(adapter); } }; private void updateUI() { if (fAuth.getCurrentUser() != null){ Log.i("MainActivity", "fAuth != null"); } else { Intent startIntent = new Intent(NotesMine.this, MainActivity.class); startActivity(startIntent); finish(); Log.i("MainActivity", "fAuth == null"); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case R.id.main_new_note_btn: Intent newIntent = new Intent(NotesMine.this, NewNoteActivity.class); startActivity(newIntent); break; } return true; } /** * Converting dp to pixel */ private int dpToPx(int dp) { Resources r = getResources(); return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics())); } 

}

  • Read the latest documentation, the designer's signature has changed in version 3.x: github.com/firebase/FirebaseUI-Android/tree/master/… - Eugene Krivenja
  • @EugeneKrivenja I apologize, but I'm a newbie and they just don’t get to me how to change this block of code to work correctly. Perhaps you could help me with this, if it is of course not difficult for you. - Vlad Antipin

2 answers 2

The code should be something like this:

 FirebaseRecyclerOptions<NoteModel> options = new FirebaseRecyclerOptions.Builder<NoteModel>() .setQuery(query, NoteModel.class) .build(); FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(options) { @Override public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.activity_notes, parent, false); return new NoteViewHolder(view); } @Override protected void onBindViewHolder(NoteViewHolder holder, int position, NoteModel model) { // Сюда перенесете код из populateViewHolder() // ... } }; 
  • It does not generate errors, but does not display information. - Vlad Antipin
  • information is written to the database, but is not displayed in the application, what should I do? - Vlad Antipin
  • Add before .build(); the line .setLifecycleOwner(NotesMine.this) or do so github.com/firebase/FirebaseUI-Android/blob/master/firestore/… - woesss
  • @EugeneKrivenja That's the mistake. When I get to .build (); all my variables are still null for some reason, they don’t get anything assigned - Vlad Antipin
  • @EugeneKrivenja Here is the moto code on the gita github.com/AntipinVlad/ProgLand2.git - Vlad Antipin

This code is correct for this type of task:

 public class NotesMine extends AppCompatActivity { private FirebaseAuth fAuth; private RecyclerView mNotesList; private GridLayoutManager gridLayoutManager; private DatabaseReference fNotesDatabase; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); mNotesList = (RecyclerView) findViewById(R.id.notes_list); gridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false); mNotesList.setHasFixedSize(true); mNotesList.setLayoutManager(gridLayoutManager); mNotesList.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true)); fAuth = FirebaseAuth.getInstance(); if (fAuth.getCurrentUser() != null) { fNotesDatabase = FirebaseDatabase.getInstance().getReference().child("Notes").child(fAuth.getCurrentUser().getUid()); } updateUI(); loadData(); } @Override public void onStart() { super.onStart(); } private void loadData() { Query query = fNotesDatabase; FirebaseRecyclerOptions<NoteModel> options = new FirebaseRecyclerOptions.Builder<NoteModel>() .setQuery(query, NoteModel.class) .setLifecycleOwner(NotesMine.this) .build(); final FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(options) { @Override public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.activity_notes, parent, false); return new NoteViewHolder(view); } @Override protected void onBindViewHolder(final NoteViewHolder holder, int position, NoteModel model) { final String noteId = getRef(position).getKey(); fNotesDatabase.child(noteId).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.hasChild("title") && dataSnapshot.hasChild("timestamp")) { String title = dataSnapshot.child("title").getValue().toString(); String timestamp = dataSnapshot.child("timestamp").getValue().toString(); holder.setNoteTitle(title); GetTimeAgo getTimeAgo = new GetTimeAgo(); holder.setNoteTime(getTimeAgo.getTimeAgo(Long.parseLong(timestamp), getApplicationContext())); holder.noteCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(NotesMine.this, NewNoteActivity.class); intent.putExtra("noteId", noteId); startActivity(intent); } }); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } }; mNotesList.setAdapter(adapter); } private void updateUI() { if (fAuth.getCurrentUser() != null){ Log.i("MainActivity", "fAuth != null"); } else { Intent startIntent = new Intent(NotesMine.this, MainActivity.class); startActivity(startIntent); finish(); Log.i("MainActivity", "fAuth == null"); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case R.id.main_new_note_btn: Intent newIntent = new Intent(NotesMine.this, NewNoteActivity.class); startActivity(newIntent); break; } return true; } private int dpToPx(int dp) { Resources r = getResources(); return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics())); } }