【发布时间】:2020-08-03 17:12:34
【问题描述】:
我想从 Activity 调用 Fragment 类中的一个方法。使用
getFragmentManager().findFragmentById(R.id.example_fragment)
一直导致错误
Attempt to invoke virtual method 'void com.package.name.HomeFragment.functionName()' on a null object reference.
我认为这可能与我使用的是导航抽屉有关,因此我没有直接运行getSupportFragmentManager.beginTransaction.add(fragmentStuff).commit();,但我不确定如何修复此错误。
【问题讨论】:
标签: android android-studio android-fragments android-activity android-navigation