title: Fragment cannot be cast to java.util.concurrent.Executor error
body: <p>I'm attempting to sign in or sign up using fragments, and after a successful sign-in/sign up, the <code>HomeActivity</code> supposed to load. The issue is that when I click the sign-in/sign up button, it returns to the same fragment instead of going to the <code>HomeActivity.class</code>. The app's initialization page is called LoginRegistrationActivity.class where it will call the <code>SignIn</code> fragment. I confirmed that Sign in/Sign Up is working well, but I am unable to navigate to the <code>HomeActivity.class</code> after successful authentication. I'm not sure if there is an issue with the AndroidManifest.xml file.</p>
  <p>I got this logcat error after I clicked sign in:</p>
  <blockquote>
  <p>java.lang.ClassCastException: com.fyp.selfzen.fragments.O_LoginRegistration.SignIn cannot be cast to java.util.concurrent.Executor
  at com.fyp.selfzen.fragments.O_LoginRegistration.SignIn.login(SignIn.java:124)
  at com.fyp.selfzen.fragments.O_LoginRegistration.SignIn$1.onClick(SignIn.java:87)
  at android.view.View.performClick(View.java:7448)
  at android.view.View.performClickInternal(View.java:7425)
  at android.view.View.access$3600(View.java:810)
  at android.view.View$PerformClick.run(View.java:28305)
  at android.os.Handler.handleCallback(Handler.java:938)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:223)
  at android.app.ActivityThread.main(ActivityThread.java:7656)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)</p>
  </blockquote>
  <p>SignIn.java fragment</p>
  <pre><code>public class SignIn extends Fragment{
      private EditText editText_email, editText_password;
      private String email, password;
      private FirebaseAuth firebaseAuth;
      private ProgressDialog progressDialog;
  
  LoginRegisrationActivity loginRegistration;
  
  public SignIn(LoginRegisrationActivity loginRegistration) {
      this.loginRegistration = loginRegistration;
  }
  
  public static SignIn newInstance(LoginRegisrationActivity loginRegistration) {
      SignIn fragment = new SignIn(loginRegistration);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_login, container, false);
  
      progressDialog = new ProgressDialog(getContext());
      firebaseAuth = FirebaseAuth.getInstance();
      editText_email = view.findViewById(R.id.editText_email_login_activity);
      editText_password = view.findViewById(R.id.editText_password_login_activity);
      TextView button_login = view.findViewById(R.id.button_login_activity);
      TextView textView_signup_login = view.findViewById(R.id.textView_signup_login);
      final SmoothCheckBox checkBox = view.findViewById(R.id.checkbox_login_activity);
      checkBox.setChecked(false);
  
  
      button_login.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              email = editText_email.getText().toString();
              password = editText_password.getText().toString();
  
              editText_email.clearFocus();
              editText_password.clearFocus();
  
              login(email, password);
          }
      });
  
      textView_signup_login.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              SignUp f2 = SignUp.newInstance(loginRegistration);
              loginRegistration.loadFrag(f2, getResources().getString(R.string.regis));
          }
      });
      return view;
  }
  
  public void login(String email, String password) {
  
      editText_email.setError(null);
      editText_password.setError(null);
  
      if (!isValidMail(email) || email.isEmpty()) {
          editText_email.requestFocus();
          editText_email.setError(getResources().getString(R.string.please_enter_email));
      }
      else if(password.isEmpty()){
          editText_password.requestFocus();
          editText_password.setError(getResources().getString(R.string.please_enter_password));
      }
      else {
          progressDialog.setMessage(&quot;Please wait...&quot;);
          progressDialog.show();
          progressDialog.setCanceledOnTouchOutside(false);
  
          firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener((Executor) this, new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  if (task.isSuccessful()) {
                      Toast.makeText(getContext(), &quot;Successfully sign in!&quot;, Toast.LENGTH_LONG).show();
                    // Intent i = new Intent(loginRegistration, HomeActivity.class); //First try to go to HomeActivity
                      Intent i = new Intent(getContext(), HomeActivity.class); //Second try 
                      startActivity(i);
                      //loginRegistration.finish();
                  } else {
                      Toast.makeText(getContext(), &quot;Sign in failed&quot;, Toast.LENGTH_LONG).show();
                  }
                  progressDialog.dismiss();
              } //onComplete
          }); // firebaseAuth
      }// else
  } // login end
  }
  </code></pre>
  <p>SignUp.java fragments</p>
  <pre><code>public class SignUp extends Fragment{
      private EditText editText_name, editText_email, editText_password, editText_phoneNo;
      private String name, email, password, phoneNo;
      private ProgressDialog progressDialog;
      private FirebaseAuth firebaseAuth;
  
  LoginRegisrationActivity loginRegistration;
  
  public SignUp(LoginRegisrationActivity loginRegistration) {
      this.loginRegistration = loginRegistration;
      // Required empty public constructor
  }
  
  public static SignUp newInstance(LoginRegisrationActivity loginRegistration) {
      SignUp fragment = new SignUp(loginRegistration);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_registration, container, false);
  
      progressDialog = new ProgressDialog(getContext());
      firebaseAuth = FirebaseAuth.getInstance();
      editText_name = view.findViewById(R.id.editText_name_register);
      editText_email = view.findViewById(R.id.editText_email_register);
      editText_password = view.findViewById(R.id.editText_password_register);
      editText_phoneNo = view.findViewById(R.id.editText_phoneNo_register);
      TextView button_submit = view.findViewById(R.id.button_submit);
      TextView textView_login = view.findViewById(R.id.textView_login_register);
  
  
      // Go to login page
      textView_login.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              SignIn f1 = SignIn.newInstance(loginRegistration);
              loginRegistration.loadFrag(f1, getResources().getString(R.string.login));
          }
      });
  
  
      button_submit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              name = editText_name.getText().toString();
              email = editText_email.getText().toString();
              password = editText_password.getText().toString();
              phoneNo = editText_phoneNo.getText().toString();
  
              form();
          }
      });
      return view;
  }
  
  
  private boolean isValidMail(String email) {
      return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
  }
  
  public void form() {
  
      editText_name.setError(null);
      editText_email.setError(null);
      editText_password.setError(null);
      editText_phoneNo.setError(null);
  
      if (name.equals(&quot;&quot;) || name.isEmpty()) {
          editText_name.requestFocus();
          editText_name.setError(getResources().getString(R.string.please_enter_name));
      }
      else if (!isValidMail(email) || email.isEmpty()) {
          editText_email.requestFocus();
          editText_email.setError(getResources().getString(R.string.please_enter_email));
      }
      else if (password.equals(&quot;&quot;) || password.isEmpty()) {
          editText_password.requestFocus();
          editText_password.setError(getResources().getString(R.string.please_enter_password));
      }
      else if (phoneNo.equals(&quot;&quot;) || phoneNo.isEmpty()) {
          editText_phoneNo.requestFocus();
          editText_phoneNo.setError(getResources().getString(R.string.please_enter_phone));
      }
      else {
          editText_name.clearFocus();
          editText_email.clearFocus();
          editText_password.clearFocus();
          editText_phoneNo.clearFocus();
      }
      progressDialog.setMessage(&quot;Please wait...&quot;);
      progressDialog.show();
      progressDialog.setCanceledOnTouchOutside(false);
      firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
          @Override
          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
              if(task.isSuccessful()){
                  Toast.makeText(getContext(), &quot;Successfully registered!&quot;, Toast.LENGTH_LONG).show();
                  //Intent i = new Intent(loginRegistration, HomeActivity.class);
                  Intent i = new Intent(getActivity(), HomeActivity.class);
                  startActivity(i);
                  //loginRegistration.finish();
              }
              else{
                  Toast.makeText(getContext(), &quot;Sign up failed&quot;, Toast.LENGTH_LONG).show();
              }
              progressDialog.dismiss();
          }
      });
  } // end of form
  }
  </code></pre>
  <p>LoginRegistrationActivity.class</p>
  <pre><code>public class LoginRegisrationActivity extends AppCompatActivity {
      private String curent;
      VideoView vide;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login_regisration);
  
          vide = findViewById(R.id.vide);
          String video_url = &quot;android.resource://&quot; + getPackageName() + &quot;/&quot; + R.raw.login_video;
          Uri videoUri = Uri.parse(video_url);
          vide.setVideoURI(videoUri);
          vide.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
              @Override
              public void onPrepared(MediaPlayer mp) {
                  mp.setLooping(true);
                  vide.requestFocus();
                  vide.start();
              }
          });
  
          SignIn f1 = SignIn.newInstance(this);
          loadFrag(f1, getResources().getString(R.string.login));    
      }
  
  
      public void loadFrag(Fragment f1, String name) {
  
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  
          if(!name.equals(curent)){
              curent =name;
              ft.replace(R.id.frame_layout, f1, name);
          }
  
          ft.commitAllowingStateLoss();
  
      }
  
  
  }
  </code></pre>
  <p>AndroidManifest.xml</p>
  <pre><code>    &lt;activity
          android:name=&quot;com.fyp.selfzen.activities.LoginRegisrationActivity&quot;
          android:screenOrientation=&quot;portrait&quot; /&gt;
      &lt;activity
          android:name=&quot;com.fyp.selfzen.activities.HomeActivity&quot;
          android:label=&quot;@string/title_activity_home&quot;
          android:launchMode=&quot;singleTop&quot;
          android:screenOrientation=&quot;portrait&quot;
          android:windowSoftInputMode=&quot;adjustPan&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
          &lt;/intent-filter&gt;
  
          &lt;meta-data
              android:name=&quot;android.app.searchable&quot;
              android:resource=&quot;@xml/searchable&quot; /&gt;
      &lt;/activity&gt;
  
      
  </code></pre>