删除Android Studio“方法调用”' GetFragment'可能会产生NullPoInterException;警告?
Android Studio给我警告方法调用'GetFragment'可能会在以下语句中产生'NullPoInterException'
,
toSwitch = ((LoginActivity) getActivity()).getFragment(LoginFragment.class.getName());
我读了与此有关的其他问题,他们说使用essertertion或objects.requirenonnnull(requirenonNull(),但这不是我想要的。
在将其标记为重复之前
方法getFragment(字符串名称)
可以返回null值,这是必需的行为。我如何告诉Android Studio我需要该无效的值,这是完全可以的。
Android studio gives me warning Method invocation 'getFragment' may produce 'NullPointerException'
on the following statement
toSwitch = ((LoginActivity) getActivity()).getFragment(LoginFragment.class.getName());
I have read other question relating to this they say to use assertion or Objects.requireNonNull()
but this is not I want.
Before Marking this as duplicate
The method getFragment(String name)
can return null value and it is a required behavior. How can I tell android studio that I need that null value and it is perfectly ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论