I'm working on a simple Android project which can insert and retrieve data from Firebase. The inserting function works well, which means the project has successfully connected to the Firebase database. However, the retrieving part doesn't work. I did many tests and think the problem is in the FirebaseHelper because when I tried to print the result of "firebasehelper.retrieveMajor()" in the Activity, it shows nothing. But it did show the data when printing data in FirebaseHelper. You can see the codes as followings.

Model:

```
@IgnoreExtraProperties
public class Major {

    public String major_id;
    public String major_name;

    public Major() {
    }

    public Major(String major_id, String major_name) {
        this.major_id = major_id;
        this.major_name = major_name;
    }

    public String getMajor_id() {
        return major_id;
    }

    public String getMajor_name() {
        return major_name;
    }
}

```

Adapter:

```
public class MajorListAdapter extends BaseAdapter {
    Context context;
    ArrayList<Major> majors;

    public MajorListAdapter(Context context, ArrayList<Major> majors) {
        this.context = context;
        this.majors = majors;
    }

    @Override
    public int getCount() {
        return majors.size();
    }

    @Override
    public Object getItem(int pos) {
        return majors.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        if(convertView==null)
        {
            convertView= LayoutInflater.from(context).inflate(R.layout.model,viewGroup,false);
        }

        TextView tv_majorid= (TextView) convertView.findViewById(R.id.tx_majorid);
        TextView tv_majorname= (TextView) convertView.findViewById(R.id.tx_majorname);

        final Major major= (Major) this.getItem(position);

        tv_majorid.setText(major.getMajor_id());
        tv_majorname.setText(major.getMajor_name());

        return convertView;
    }

}

```

FirebaseHelper:

```
public class FirebaseHelper {

    DatabaseReference db;
    Boolean saved=null;
    ArrayList<Major> majors = new ArrayList<>();

    public FirebaseHelper(DatabaseReference db) {
        this.db = db;
    }

    //Save the Major info. into db
    public Boolean saveMajor(Major major)
    {
        if(major==null)
        {
            saved=false;
        }else
        {
            try
            {
                db.child("Major").push().setValue(major);
                saved=true;

            }catch (DatabaseException e)
            {
                e.printStackTrace();
                saved=false;
            }
        }

        return saved;
    }

    private void fetchDataFromMajor(DataSnapshot dataSnapshot) {
        majors.clear();

        for (DataSnapshot ds : dataSnapshot.getChildren()) {
            Major major = ds.getValue(Major.class);
            majors.add(major);
        }

    }

    public ArrayList<Major> retrieveMajor() {

        db.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                fetchDataFromMajor(dataSnapshot);                  
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                fetchDataFromMajor(dataSnapshot);

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

        return majors;
    }
}

```

The Activity that retrieves data and binds the data with the ListView:

```
public class MajorListActivity extends AppCompatActivity {

    DatabaseReference db;
    FirebaseHelper firebasehelper;
    MajorListAdapter adapter;
    ListView lv_MajorList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_major_list);

        lv_MajorList = (ListView) findViewById(R.id.lv_MajorList);

        db= FirebaseDatabase.getInstance().getReference();
        firebasehelper=new FirebaseHelper(db);

        //ADAPTER
        adapter = new MajorListAdapter(getApplicationContext(),firebasehelper.retrieveMajor());

        lv_MajorList.setAdapter(adapter);
    }

}

```