I want to click the button and open another fragment, but I get the following problem. What do I need to do to switch to a new fragment?
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{...yeniKayıtFragment}: java.lang.ClassCastException: ...yeniKayıtFragment cannot be cast to android.app.Activity
Firs Fragment
public class GirisFragmentNew extends Fragment implements View.OnClickListener{
btnKAyit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getActivity(), yeniKayıtFragment.class);
startActivity(i);
}
});
}
Second Fragment
public class yeniKayıtFragment extends Fragment {
private yeniKayıtModel yeniKayıtModel;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
yeniKayıtModel =
ViewModelProviders.of(this).get(yeniKayıtModel.class);
View root = inflater.inflate(R.layout.fragment_yenikayit, container, false);
Window window=getActivity().getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setNavigationBarColor(getResources().getColor(R.color.colorPrimary));}
return root;
}
ViewModel
package ...yeniKayit;
import androidx.lifecycle.ViewModel;
public class yeniKayıtModel extends ViewModel {
}