1

I want to separate my admin user and student user, so I've created a key on my Firestore database named 'userType', and I've used fragments to make a login and signup form. In signup form, I've fetched data, and when I login initially, it works fine. However, when I reopen my app, it just crashes. I've written code in signup form for sending logged in users to different activities according to their user type. I edited one key as admin in Firestore.

SignupTabFragment, here's the problem.

package com.example.mkmaterials;


public class SignupTabFragment extends Fragment {

public static final String TAG = "TAG";
EditText signupName,signupEmail,signupPassword,signupConfirmPassword;
boolean signupPasswordVisible,signupRepeatPasswordVisible;
Button signup;
private FirebaseAuth firebaseAuth;
private FirebaseFirestore firestore;
String signupUserType = "Student";
String userID;
private String userIDFireStore,userTypeFirestore;
ProgressBar signupProgressBar;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.signup_tab_fragment,container,false);

    signupName = root.findViewById(R.id.edt_SignupName);
    signupEmail = root.findViewById(R.id.edt_SignupEmail);
    signupPassword = root.findViewById(R.id.edt_SignupPassword);
    signupConfirmPassword = root.findViewById(R.id.edt_SignupConfirmPassword);
    signup = root.findViewById(R.id.btn_Signup);

    firebaseAuth = FirebaseAuth.getInstance();
    firestore = FirebaseFirestore.getInstance();
    signupProgressBar = root.findViewById(R.id.progress_SignupProgressBar);

This is The Problematic Area

if(firebaseAuth.getCurrentUser() != null){
        // Retrieving User Data From Firebase
        userIDFireStore = firebaseAuth.getCurrentUser().getUid();
        DocumentReference documentReference = firestore.collection("users").document(userIDFireStore);
        documentReference.addSnapshotListener(getActivity(), new EventListener<DocumentSnapshot>() {
            @Override
            public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
                userTypeFirestore = value.getString("userType");
                if(userTypeFirestore.equals("Admin")){
                    startActivity(new Intent(getActivity().getApplicationContext(),AdminHomeActivity.class));
                    getActivity().finish();
                }
                if(userTypeFirestore.equals("Student")){
                    startActivity(new Intent(getActivity().getApplicationContext(),HomeActivity.class));
                    getActivity().finish();
                }
            }
        });
    }
  • Does this answer your question? [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – a_local_nobody Oct 01 '21 at 08:33
  • 1
    That's too much going on here. If you encounter problems, it's best to create a [MCVE](https://stackoverflow.com/help/mcve) when posting a question. You posted almost **700 (seven hundred)** lines of code for this issue. That's a lot for people to parse and try to debug online. Please edit your question and isolate the problem, in that way you increase your chances of being helped. – Alex Mamo Oct 01 '21 at 08:38
  • Besides that, if the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. – Alex Mamo Oct 01 '21 at 08:38
  • Thanks A Lot Alex That's A Great Help From You, I'm New Here And Don't Know What To Do And What Not To Do.. Thanks For Giving Some Clearity! – Krutarth Vaishnav Oct 01 '21 at 20:36

0 Answers0