Android 深入阅读firebase数据库
我的目标是在列表视图中显示锦标赛的名称 这就是我的数据库的外观: 我用于填充列表视图的代码如下所示:Android 深入阅读firebase数据库,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我的目标是在列表视图中显示锦标赛的名称 这就是我的数据库的外观: 我用于填充列表视图的代码如下所示: //list view to be populated with tournament data final ListView tournamentListView= (ListView) findViewById(R.id.list); //finding and setting the empty view in the listView when the list ha
//list view to be populated with tournament data
final ListView tournamentListView= (ListView) findViewById(R.id.list);
//finding and setting the empty view in the listView when the list has 0 items
View emptyView = findViewById(R.id.empty_view);
tournamentListView.setEmptyView(emptyView);
final ArrayList<String> tournamentNamesList = new ArrayList<String>();
DatabaseReference tournamentRef = mDatabase.child("Tournaments");
tournamentRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot tournamentIds: dataSnapshot.getChildren()) {
for (DataSnapshot tournament : tournamentIds.getChildren()) {
TournamentInformation tournamentInformation = new TournamentInformation();
tournamentInformation.setTournamentName(tournament.getValue(TournamentInformation.class).getTournamentName());
tournamentNamesList.add(tournamentInformation.getTournamentName());
Log.d("Main Activity", tournamentInformation.getTournamentName());
}
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this,android.R.layout.simple_list_item_1,tournamentNamesList);
tournamentListView.setAdapter(arrayAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
//要用比赛数据填充的列表视图
最终ListView锦标赛ListView=(ListView)findViewById(R.id.list);
//当列表包含0项时,在listView中查找和设置空视图
视图emptyView=findViewById(R.id.empty\u视图);
tournamentListView.setEmptyView(emptyView);
最终ArrayList TournamentNameList=新ArrayList();
DatabaseReference tournamentRef=mDatabase.child(“Tournaments”);
tournamentRef.addValueEventListener(新的ValueEventListener(){
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot){
对于(DataSnapshot TournamEntId:DataSnapshot.getChildren()){
对于(DataSnapshot锦标赛:tournamentIds.getChildren()){
TournamentFormation TournamentFormation=新的TournamentFormation();
setTournamentName(tourbank.getValue(tournamentInformation.class.getTournamentName());
tournamentNamesList.add(tournamentInformation.getTournamentName());
Log.d(“主要活动”,tournamentInformation.getTournamentName());
}
}
ArrayAdapter ArrayAdapter=新的ArrayAdapter(MainActivity.this,android.R.layout.simple\u list\u item\u 1,tournamentNamesList);
setAdapter(arrayAdapter);
}
@凌驾
已取消的公共void(DatabaseError DatabaseError){
}
});
我的应用程序在启动时崩溃,我在logcat中收到以下消息:
请修复应用程序以正确结束正在进行的事务,并在不再需要时关闭数据库
数据库“/data/user/0/com.google.android.gms/databases/help_responses.db.18”的SQLiteConnection对象泄漏!请修复应用程序以正确结束正在进行的事务,并在不再需要时关闭数据库
数据库“/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db”的SQLiteConnection对象泄漏!请修复应用程序以正确结束正在进行的事务,并在不再需要时关闭数据库
我不知道这些错误是什么意思,主要是因为我没有使用SQLite
有人知道发生了什么事吗
提前谢谢 虽然Firebase确实在内部使用SQLite进行磁盘持久化,但错误消息似乎与此无关。是否有任何其他错误消息/堆栈跟踪指向您共享的代码中的某些内容?为什么是第二个循环?您的数据没有反映第二个循环的需要抱歉,我对快照的理解不正确。。我修正了这一点,但没有任何区别-应用程序仍然会崩溃,并在logcat@thunder413中显示相同的消息。没有发现其余代码有任何错误。你能发布完整的堆栈跟踪让它工作吗。。我刚刚清理并重建了这个项目。谢谢@雷霆413