gpt4 book ai didi

java - 错误 : no suitable method found for setQuery(com. google.firebase.firestore.Query,Class<注意>)

转载 作者:行者123 更新时间:2023-12-01 18:39:02 24 4
gpt4 key购买 nike

我正在尝试从 FirebaseFirestore 获取数据并在卡片 View 中实现它。

这是我的代码

public class MainActivity extends AppCompatActivity { 

private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference notebookRef = db.collection("Notebook");

//notebookref is my collection name in firebase.
private NoteAdapter adapter;

TextView tv_id;
TextView tv_attend;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv_id=findViewById(R.id.tv_id);
tv_attend=findViewById(R.id.tv_attend);

setUpRecyclerView();
}

private void setUpRecyclerView() {
Query query = notebookRef.orderBy("attend", Query.Direction.DESCENDING);

FirebaseRecyclerOptions<Note> options = new FirebaseRecyclerOptions.Builder<Note>()
.setQuery(query, Note.class)
.build();

adapter = new NoteAdapter(options);

RecyclerView recyclerView = findViewById(R.id.rv_one);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);

}

@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}

@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}

我收到以下错误:

error: no suitable method found for setQuery(com.google.firebase.firestore.Query,Class<Note>)

似乎我有以下问题:FirebaseRecyclerOptions.Builder().setQuery(query, Note.class).build();

有关如何处理此问题的任何指示吗?

最佳答案

检查您导入的查询。您应该导入

import com.google.firebase.firestore.Query;

更多详情

orderBy(String field, Query.Direction direction)

创建并返回一个新查询,该查询还按指定字段排序,可以选择按降序而不是升序排序。

引用号。 https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/Query

相应地确认您的依赖项

dependencies {
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:6.2.0'

// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:6.2.0'

// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:6.2.0'

// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
}

引用号。 https://github.com/firebase/FirebaseUI-Android

关于java - 错误 : no suitable method found for setQuery(com. google.firebase.firestore.Query,Class<注意>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59981652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com