我的EventListener跳过OnDataChange到OnCancelled。 Android Studio在编译应用程序时未显示任何错误。但是,当我尝试从Firebase检索数据时出现问题。
uploads = new ArrayList<>();
mDatabase = FirebaseDatabase.getInstance().getReference(Constants.DATABASE_PATH_UPLOADS);
//adding an event listener to fetch values
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
//dismissing the progress dialog
progressDialog.dismiss();
//iterating through all the values in database
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Upload upload = postSnapshot.getValue(Upload.class);
uploads.add(upload);
}
//creating adapter
adapter = new MyAdapter(getApplicationContext(), uploads);
//adding adapter to recyclerview
//MyAdapter adapter = new MyAdapter(new ArrayList<String>(list));
recyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(),"Error connecting to database", Toast.LENGTH_SHORT).show();
//progressDialog.dismiss();
}
});