This is mydatabase on firebase
我正在从Firebase添加数据,但是在手机中运行该应用程序时,RecyclerView为空白,并且从Oncancelled方法中收到错误消息。 我的数据库包含四个字段,名称,电子邮件,权限和链接(字符串)。
public class MainActivity extends AppCompatActivity {
DatabaseReference reference;
RecyclerView recyclerView;
ArrayList<Profile> list;
MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.myRecycler);
recyclerView.setLayoutManager( new LinearLayoutManager(this));
reference = FirebaseDatabase.getInstance().getReference().child("Profile");
list = new ArrayList<Profile>();
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Toast.makeText(MainActivity.this, "Inside the data change", Toast.LENGTH_SHORT).show();
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
Toast.makeText(MainActivity.this, "Inside the for loop", Toast.LENGTH_SHORT).show();
Profile p = dataSnapshot1.getValue(Profile.class);
list.add(p);
}
adapter = new MyAdapter(MainActivity.this,list);
recyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(MainActivity.this, "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
}
});
}
}