原因:java.lang.NullPointerException:尝试调用虚拟方法'com.google.firebase.database.ChildEventListener

时间:2019-09-20 18:17:32

标签: java android-studio nullpointerexception

我有此错误,我不知道如何解决

原因:java.lang.NullPointerException:尝试调用虚拟方法“ com.google.firebase.database.ChildEventListener com.google.firebase.database.Query.addChildEventListener(com.google.firebase.database.ChildEventListener)”在空对象引用上

enter code here

    RecyclerView mRecyclerView;
FirebaseDatabase mFirebaseDatabase;
DatabaseReference mRef;     

    //ActionBar
    ActionBar actionBar = getSupportActionBar();
    //set title
    actionBar.setTitle("List");

// RecyclerView         mRecyclerView = findViewById(R.id.recyclerView);         mRecyclerView.setHasFixedSize(true);

    //layout linear
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //send query to firebase

    mFirebaseDatabase = FirebaseDatabase.getInstance();
    mRef = mFirebaseDatabase.getReference("Data");


}
//load data into recycler view onStart

@Override
protected void onStart() {
    super.onStart();
    FirebaseRecyclerAdapter<Model, ViewHolder> firebaseRecyclerAdapter =
            new FirebaseRecyclerAdapter<Model, ViewHolder>(
                    Model.class,
                    R.layout.row,
                    ViewHolder.class,
                    mRef
            ) {
                @Override
                protected void populateViewHolder(ViewHolder viewHolder, Model model, int i) {
                    viewHolder.setDetails(getApplicationContext(), model.getTitle(), model.getDescription(), model.getImage());
                }
            };

    //adapter ro recycler
    mRecyclerView.setAdapter(firebaseRecyclerAdapter);

}

}

0 个答案:

没有答案