运行代码时出现此错误:
错误:错误:类FirebaseListAdapter中的构造函数FirebaseListAdapter无法应用于给定类型; 必需:FirebaseListOptions 找到:MainActivity,Class,int,DatabaseReference 原因:实际和正式论点清单的长度不同 其中T是类型变量: T扩展了在类FirebaseListAdapter中声明的对象
这是我的代码:
private void displayChat() {
ListView listOfMessage = findViewById(R.id.list_of_message);
adapter = new FirebaseListAdapter<Chat>(this, Chat.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference()) {
@Override
protected void populateView(View v, Chat model, int position) {
//Get reference to the views of list_item.xml
TextView messageText, messageUser, messageTime;
messageText = findViewById(R.id.message_text);
messageUser = findViewById(R.id.message_user);
messageTime = findViewById(R.id.message_time);
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", model.getMessageTime()));
}
};
listOfMessage.setAdapter(adapter);
}
我尝试了https://stackoverflow.com/questions/47243957/firebase-list-adapter-constructor-error问题的替换解决方案:
adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference())
具有:
FirebaseListOptions<ChatMessage> options =
new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.setLayout(android.R.layout.simple_list_item_1)
.build();
adapter = new FirebaseListAdapter<ChatMessage>(options){
但是我得到的只是更多错误,例如unable to resolve symbol FirebaseListOptions
这是我的应用级别dependencies
:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.firebaseui:firebase-ui:4.1.0'
implementation 'com.android.support:support-core-utils:28.0.0-rc01'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.3'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
我尝试了很多版本,并且错误从未停止。