我正在学习this教程,我遇到了一些问题。我能够启动我的应用并与Firebase数据库共享消息;但是,我无法看到它们。但是现在,我收到了这个错误。
java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.furka.findit / com.example.furka.findit.ChatActivity}:java.lang.RuntimeException:Layout不能为null。调用setLayout。
这是发送消息按钮的onClick viewListener:
public void onClick(View view) {
EditText input = (EditText)findViewById(R.id.input);
// Read the input field and push a new instance
// of ChatMessage to the Firebase database
FirebaseDatabase.getInstance()
.getReference()
.push()
.setValue(new ChatMessage(input.getText().toString(),
FirebaseAuth.getInstance()
.getCurrentUser()
.getEmail())
);
input.setText("");
这是观看的方法。
private void displayChatMessages() {
ListView listOfMessages = (ListView)findViewById(R.id.list_of_messages);
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.build();
adapter = new FirebaseListAdapter<ChatMessage>(options) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Get references to the views of message.xml
TextView messageText = (TextView)v.findViewById(R.id.message_text);
TextView messageUser = (TextView)v.findViewById(R.id.message_user);
TextView messageTime = (TextView)v.findViewById(R.id.message_time);
// Set their text
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
// Format the date before showing it
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
model.getMessageTime()));
}
};
listOfMessages.setAdapter(adapter);
}