Android Application crashes when I switch to a fragment after I tried implementing Firebase Realtime Database

I had it working with SQLite database but then when I tried to switch to Firebase Real-time Database it decided to start crashing on me… I’m completely lost on this one. Some help would be much appreciated.

Here is my Fragment

package com.example.goalhero;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import static android.app.Activity.RESULT_OK;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class FragDailies extends Fragment {
    Button newDailyBtn;
    RecyclerView dailiesRecyclerView;
    RecyclerViewAdapterDailies adapter;
    final static int requestCodeForCreateNewDailyActivityCall = 2;
    ArrayList<DataDaily> dailies;
    private DatabaseReference dailiesDatabaseReference;
    private DailiesLifecycleObserver lifecycleObserver = new DailiesLifecycleObserver();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        dailiesDatabaseReference = database.getReference("dailies");
        dailies = new ArrayList<>();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_dailies, container, false);
        dailiesRecyclerView = rootView.findViewById(R.id.dailiesRecyclerView);
        dailiesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new RecyclerViewAdapterDailies(getContext(), dailies);
        dailiesRecyclerView.setAdapter(adapter);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        newDailyBtn = view.findViewById(R.id.launchCreateNewDailyActivityBtn);
        newDailyBtn.setOnClickListener(v -> {
            Intent intent = new Intent(getContext(), CreateNewDailyActivity.class);
            startActivityForResult(intent, requestCodeForCreateNewDailyActivityCall);
        });
        loadDailiesFromFirebase();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == requestCodeForCreateNewDailyActivityCall && resultCode == RESULT_OK) {
            if (!data.getStringExtra("title").equals("")) {
                DataDaily curDaily = new DataDaily(data.getBooleanExtra("mon", true),
                        data.getBooleanExtra("tues", true),
                        data.getBooleanExtra("wed", true),
                        data.getBooleanExtra("thurs", true),
                        data.getBooleanExtra("fri", true),
                        data.getBooleanExtra("sat", true),
                        data.getBooleanExtra("sun", true), false,
                        data.getBooleanExtra("isEasy", true),
                        data.getStringExtra("title"),
                        data.getStringExtra("timeframe"),
                        data.getStringExtra("reps"));
                addDailyToFirebase(curDaily);
            }
        }
    }

    private void addDailyToFirebase(DataDaily daily) {
        dailiesDatabaseReference.push().setValue(daily)
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        Toast.makeText(getContext(), "Daily added successfully", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(getContext(), "Failed to add daily", Toast.LENGTH_LONG).show();
                    }
                });
    }

    private void loadDailiesFromFirebase() {
        dailiesDatabaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                dailies.clear();
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    DataDaily daily = postSnapshot.getValue(DataDaily.class);
                    if (daily != null) {
                        dailies.add(daily);
                    } else {
                        // Log the issue if daily is null
                        System.out.println("DataDaily is null for snapshot: " + postSnapshot.getKey());
                    }
                }
                adapter.setDailies(dailies);
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Toast.makeText(getContext(), "Failed to load dailies: " + databaseError.getMessage(), Toast.LENGTH_LONG).show();
                // Log the error message
                System.out.println("DatabaseError: " + databaseError.getMessage());
            }
        });
    }


    public void addDaily(String title, String timeframe, String reps, boolean mon, boolean tues, boolean wed, boolean thurs, boolean fri, boolean sat, boolean sun, boolean isEasy, boolean isHard) {
        DataDaily daily = new DataDaily(mon, tues, wed, thurs, fri, sat, sun, false, isEasy, title, timeframe, reps);
        addDailyToFirebase(daily);
    }

    private class DailiesLifecycleObserver {
        public void onResumeFragment() {
            loadDailiesFromFirebase();
        }
    }
}

You might also want to look at the RecyclerViewAdapter

package com.example.goalhero;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

public class RecyclerViewAdapterDailies extends RecyclerView.Adapter<RecyclerViewAdapterDailies.ViewHolder> {
    private ArrayList<DataDaily> dailies;
    private Context context;
    private DatabaseReference dailiesDatabaseReference;

    // Constructor
    public RecyclerViewAdapterDailies(Context context, ArrayList<DataDaily> dailies) {
        this.context = context;
        this.dailies = dailies;

        FirebaseDatabase database = FirebaseDatabase.getInstance();
        dailiesDatabaseReference = database.getReference("dailies");
    }

    // Set dailies data
    public void setDailies(ArrayList<DataDaily> dailies) {
        this.dailies = dailies;
        notifyDataSetChanged();
    }

    // ViewHolder class
    public class ViewHolder extends RecyclerView.ViewHolder {
        private CheckBox dailyListItemCB;
        private TextView dailyTextView;
        private ImageView deleteImage;
        private RelativeLayout parent;

        // Constructor
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            parent = itemView.findViewById(R.id.parent);
            dailyListItemCB = itemView.findViewById(R.id.list_itemCB);
            dailyTextView = itemView.findViewById(R.id.textView);
            deleteImage = itemView.findViewById(R.id.imageViewDeleteDaily);
        }
    }

    // onCreateViewHolder
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dailies_list_item, parent, false);
        return new ViewHolder(view);
    }

    // onBindViewHolder
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        // Narrows it down to just one daily
        final DataDaily currentDaily = dailies.get(position);

        // Bind data to views
        holder.dailyListItemCB.setText(currentDaily.getInfo());
        if (!currentDaily.timeFrame.equals("")) {
            holder.dailyTextView.setText(currentDaily.timeFrame);
        }

        holder.dailyListItemCB.setChecked(currentDaily.completedToday);

        holder.dailyListItemCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                currentDaily.completedToday = isChecked;
                updateCompletionStatusInFirebase(currentDaily);

                // Notify the adapter about the item change
                notifyDataSetChanged();

                // Create an instance of the Random class
                Random random = new Random();
                // Generate a random number between 1 and 10
                int randomNumber = random.nextInt(10) + 1;

                // Check if the click count is 10
                if (randomNumber == 10) {
                    // Show the popup window
                    if (context instanceof ActivityMain) {
                        ((ActivityMain) context).showPopupWindow();
                    }
                }
            }
        });

        holder.deleteImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteDailyFromFirebase(currentDaily);
            }
        });
    }

    // getItemCount
    @Override
    public int getItemCount() {
        return dailies.size();
    }

    // Helper methods to interact with Firebase
    private void updateCompletionStatusInFirebase(DataDaily daily) {
        dailiesDatabaseReference.child(daily.getDailyID()+"").setValue(daily)
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        Toast.makeText(context, "Status updated successfully", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(context, "Status update failed", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    private void deleteDailyFromFirebase(DataDaily daily) {
        dailiesDatabaseReference.child(daily.getDailyID()+"").removeValue()
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        dailies.remove(daily);
                        notifyDataSetChanged();
                        Toast.makeText(context, "Daily deleted successfully", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(context, "Failed to delete daily", Toast.LENGTH_SHORT).show();
                    }
                });
    }
}

I’m completely lost here I just started using Firebase so I have no idea… Also I’m a newbie to programming.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật