Tell me why entered incorrectly? In many examples, this is how work with dynamic control of fragments is shown.

Закрашивается androidx.fragment.app.FragmentTransaction

 public class TranslateActivity extends AppCompatActivity { EnglishFragment EnglishFrag; FragmentTransaction ft; JapaniseFragment JapFrag; ChineseFragment ChinaFrag; RussianFragment RussFrag; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_translate); FragmentManager fragmentManager = getFragmentManager(); //ошибка на строчке ниже FragmentTransaction ft = fragmentManager.beginTransaction(); EnglishFragment EnglishFrag = new EnglishFragment(); ft.add(R.id.Tranlation, EnglishFrag, "fragment1"); ft.commit(); } 

}

  • one
    most likely, you are using a fragment (or FragmentTransaction ) from the support library, and the manager is a normal one. Replace getFragmentManager() with getSupportFragmentManager() - Jarvis_J pm
  • androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager (); Thank you, it began to work after such a change :) But this is why?) I have never met anything like this - Aleksey Paul
  • because the support library classes and API classes are different classes and do not mutually replace each other. you use fragments from the support library, and you want to manage them using API tools, see importing classes - pavlofff

0