【发布时间】:2019-01-06 17:29:25
【问题描述】:
您好,我正在尝试通过单击片段中的按钮来了解如何替换片段。
我尝试查看此article,但它对我不起作用。
View view = getSupportFragmentManager().findFragmentById(R.id.fragment_container).getView();
btnGoToSignUp = view.findViewById(R.id.btnGoToSignUp);
我试过了,但它出现了错误
原因:java.lang.NullPointerException:尝试调用虚拟 方法'android.view.View android.support.v4.app.Fragment.getView()' 在空对象引用上
【问题讨论】:
-
getSupportFragmentManager().findFragmentById(R.id.fragment_container)=null这意味着您的片段甚至不存在,即当您尝试访问片段的视图时片段被破坏