フラグメントのスワップに使用するコードを置き換えるメソッドを作成して、コピーと投稿を最小限に抑える (そして DRY を維持する) 方法を作成しようとしています。
問題引数として渡したクラスを使用して、そのクラスの新しいインスタンスを作成しようとすると、エラーが発生します。
エラーは、次のコード行の演算子 (等号) の左側で発生します。
newFragmentClass new_fragment = newFragmentClass.newInstance();     
それが私に与えるエラーは、「newFragmentClassを型に解決できません」です。
完全なコード    private void changeFragment(Class<?> newFragmentClass)
    {
        // Detect the current fragment
            Fragment current_fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    
        // Create a new instance of the given class, edit later to gracefully handle errors
            newFragmentClass new_fragment = newFragmentClass.newInstance(); 
            
        // Switch to the new fragment
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.detach(current_fragment);
            transaction.replace(R.id.fragment_container, new_fragment);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            transaction.commit();
            
        // Change the tab background to indicate that the tab is active, reset backgrounds for any other tabs
            findViewById(R.id.page_one_tab).setBackgroundResource(R.drawable.menu_button_background_active);
            findViewById(R.id.page_two_tab).setBackgroundResource(R.drawable.menu_button_background);
            findViewById(R.id.page_three_tab).setBackgroundResource(R.drawable.menu_button_background);
    
    }
    
    // Page One Tab Button Functionality
    public void pageOneTab (View v)
    {
        // Change the fragment to SelectPlayersFragment
        changeFragment(Page_One_Fragment.class);
    }
試みられた解決策
StackOverflow とインターネット全体をかなり長い間検索してきましたが、解決策を見つけることができませんでした。このようないくつかのトピックは問題を解決するように見えましたが、その後、transaction.replace 行でエラーが発生し、修正が見つかりませんでした。は引数 (int、Object) には適用されません。」