findFragmentById return null

后端 未结 5 1111
时光取名叫无心
时光取名叫无心 2020-12-09 15:01

When i call findFragmentById() with the id of my fragment, it return null. Let me show you the code.

The activity_main.xml



        
5条回答
  •  我在风中等你
    2020-12-09 15:25

    just found out my mistake.

    In my MainActivity.java i was importing android.support.v4.app.Fragment; and in my LoginFragment.java i was importing android.app.Fragment;. I changed it to the same thing and fm.findFragmentById(R.id.login_fragment) now return the right fragment.

提交回复
热议问题