我的应用程序的 Java 代码遇到问题
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
{
Message message = dataSnapshot.getValue(Message.class);
message.setKey(dataSnapshot.getKey());
messages.add(message);
displayMessages(messages);
}
抛出错误:"cannot resolve method"
最佳答案
我认为您缺少一些东西,请尝试以下代码:
ref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String prevChildKey) {
Post newPost = dataSnapshot.getValue(Post.class);
System.out.println("Author: " + newPost.author);
System.out.println("Title: " + newPost.title);
System.out.println("Previous Post ID: " + prevChildKey);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String prevChildKey) {}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String prevChildKey) {}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
关于java - Android Studio错误 "cannot resolve method",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56333137/