所以基本上我想从Adapter过渡到片段。
AppCompatActivity activity = (AppCompatActivity) view.getContext();
Fragment fragments = new Subject_Chapter_Fragment();
FragmentManager fragmentManager = activity.getSupportFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.frame_container, fragments);
ft.commit();
java.lang.ClassCastException: android.app.Application cannot be cast to androidx.appcompat.app.AppCompatActivity
at soft.gen.studentapp.Activities.adapter.Adapter_Subjects$1.onClick(Adapter_Subjects.java:45)
答案 0 :(得分:0)
尝试获取应用上下文,然后将其投放到您的活动中
AppCompatActivity activity = (AppCompatActivity) view.getContext().getApplicationContext();