运行RecyclerView UI时出现错误
@Override
public void onStart() {
super.onStart();
final FirebaseRecyclerAdapter<request_recycle, requestViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<request_recycle, requestViewHolder>(request_recycle.class, R.layout.request_trip_layout, requestViewHolder.class, query_car) {
@Override
protected void populateViewHolder(final requestViewHolder viewHolder, final request_recycle model, int position) {
};
}
我收到此错误:
java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
at com.firebase.ui.a.b.a(Unknown Source)
at android.support.v7.widget.RecyclerView$a.b(Unknown Source)
at android.support.v7.widget.RecyclerView$p.a(Unknown Source)
at android.support.v7.widget.RecyclerView$p.a(Unknown Source)
依赖项是:
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.firebaseui:firebase-ui-database:0.4.0'
implementation 'com.firebaseui:firebase-ui-auth:3.1.0'
答案 0 :(得分:0)
将两个firebaseUI
依赖项更新为以下内容:
implementation 'com.firebaseui:firebase-ui-database:4.1.0'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
因此它们与您正在使用的Firebase库兼容,因为这可能会引起问题。
然后使用以下代码:
FirebaseRecyclerOptions<request_recycle> options =
new FirebaseRecyclerOptions.Builder<Chat>()
.setQuery(query_car, request_recycle.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<request_recycle, requestViewHolder>(options) {
@Override
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.message for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.request_trip_layout, parent, false);
return new ChatHolder(view);
}
@Override
protected void onBindViewHolder(ChatHolder holder, int position, Chat model) {
// Bind the Chat object to the ChatHolder
// ...
}
};
不要忘记阅读docs,并进行以下检查:
您需要使用adapter.startListening();
,以便数据可以显示在recyclerview中。