s = null,无法从firebase检索数据,将数据检索为null

时间:2017-02-17 21:13:03

标签: android database firebase null snapshot

我遇到了firebase的问题,因为它似乎会导致数据库的结果为null。在调试应用程序中,我可以通过以下行看到s = null:

String list_project = dataSnapshot.child("users").child("Project Name").getValue(String.class);

请参阅以下代码:

public class MainActivity2 extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    public DatabaseReference mDatabase;
    private FirebaseAuth auth;
    private ListView mProjectList;
    ArrayList<String> list_project=new ArrayList<>();
    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mProjectList = (ListView) findViewById(R.id.ProjectList);
        adapter =new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,list_project);
        mProjectList.setAdapter(adapter);

        mDatabase = FirebaseDatabase.getInstance().getReference().getRoot();
        // final DatabaseReference mRef = mDatabase.getRef();
         final DatabaseReference mRef = mDatabase.child("users");

        mRef.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {

           String list_project = dataSnapshot.child("users").child("Project Name").getValue(String.class);


                adapter.notifyDataSetChanged();
            }

0 个答案:

没有答案