我正在尝试获取新的FirebaseAdapter,但是构建后我的应用程序崩溃了。我以前从未遇到过适配器问题,但是现在我收到以下错误消息:
Class 'Anonymous class derived from FirebaseRecyclerAdapter' must either be declared abstract or implement abstract method 'onBindViewHolder(VH, int, T)' in 'FirebaseRecyclerAdapter'
此外,当我尝试构建时:
FAILED
C:\Users\Name\Desktop\MyApps\Aktuell\HTV\app\src\main\java\com\nic\htv\MainActivity.java:222: error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter<T,VH> cannot be applied to given types;
FirebaseRecyclerAdapter<NoteModel, NoteViewHolder> firebaseNotesAdapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(
^
required: FirebaseRecyclerOptions<NoteModel>
found: Class<NoteModel>,int,Class<NoteViewHolder>,Query
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
这是原始代码:
//ANFANG NOTES
private void loadData() {
Query query = fNotesDatabase.orderByValue();
final FirebaseRecyclerOptions<NoteModel> options =
new FirebaseRecyclerOptions.Builder<NoteModel>()
.setQuery(query, NoteModel.class)
.build();
FirebaseRecyclerAdapter<NoteModel, NoteViewHolder> firebaseNotesAdapter = new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(options) {
@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(MainActivity.this, NewNoteActivity.class);
intent.putExtra("noteId", noteId);
startActivity(intent);
}
});
}
}