Hello im trying to retrive data from all notes from the current logged in user.
however i keep getting this error and i dnt know how to fix this. im using Viewholder recyclerView. i also have 2 xml files 1 for the view and one for the cardview layout. however i know the problem is in my code section where i'm missing to read out the data. i saw a tutorial and we do the same thing he also creates posts with user ID and reads them out like this
Error listed below:
W/ClassMapper: No setter/field for -LxFfo5HuRPQsBUSiFuc found on class com.example.examapplikation.Models.NotesList No setter/field for -LxFfqThHtNWsk9bD5Zb found on class com.example.examapplikation.Models.NotesList No setter/field for -LxI2a7Osg8WYK1E5VJ4 found on class com.example.examapplikation.Models.NotesList
these are the IDS of my posts:
my main activity
enter code here
private RecyclerView recyclerView; //https://camposha.info/android-firebase-realtime-database-with-recyclerview/
private FloatingActionButton addNotePageButton;
private FirebaseAuth firebaseAuth;
FirebaseDatabase database;
DatabaseReference todoDb;
FirebaseRecyclerOptions<NotesList> options;
FirebaseRecyclerAdapter<NotesList, NoteViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
recyclerView = findViewById(R.id.recyclerView);
addNotePageButton = findViewById(R.id.fab_button_addPage);
firebaseAuth = FirebaseAuth.getInstance(); // get inSTACE
database = FirebaseDatabase.getInstance();
todoDb = database.getReference("NoteList");
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager( new LinearLayoutManager(this) );
showTask();
addNotePageButton.setOnClickListener(new View.OnClickListener() { // Float button click
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, NoteInputActivity.class);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
private void showTask(){
options = new FirebaseRecyclerOptions.Builder<NotesList>()
.setQuery(todoDb,NotesList.class)
.build();
adapter = new FirebaseRecyclerAdapter<NotesList, NoteViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull NoteViewHolder holder, int position, @NonNull NotesList model) {
holder.text_title.setText(model.getText());
holder.text_content.setText(model.getText());
}
@NonNull
@Override
public NoteViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.notes_each_row,viewGroup,false);
return new NoteViewHolder(itemView);
}
};
recyclerView.setAdapter(adapter);
}
here is my model class:
enter code here
public class NotesList {
private String title;
private String text;
public NotesList(){
}
public NotesList(String title, String text){
this.title=title;
this.text= text;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
here is my code of my ViewHolder:
enter code here
public class NoteViewHolder extends RecyclerView.ViewHolder {
public TextView text_title, text_content;
public NoteViewHolder(@NonNull View itemView){
super (itemView);
text_title = itemView.findViewById(R.id.text_title);
text_content = itemView.findViewById(R.id.text_content);
}
}
database strucutre picture: enter image description here
You have to go one more level in your query to get NotesList
. Change your query like below:
todoDb = database.getReference("NoteList").child("6Dp...Py1");
if 6Dp...Py1
is your current user's UID
then use
todoDb = database.getReference("NoteList").child(firebaseAuth.getCurrentUser().getUid());
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras