断言变量不为空的函数调用Asserts.checkNotNull被标记为该参数可能为空

时间:2018-10-02 13:38:38

标签: android android-studio null assert illegalargumentexception

我正在编写带有自定义支持工具栏的android应用程序。设置了supportActionbar之后,我必须使用getSupportActionbar()重新获得工具栏。由于工具栏可能为空,因此我想断言它不是。对于此断言,我使用的是checkNotNull

中的函数com.google.android.gms.common.internal.Asserts;

请参见以下代码:

setSupportActionBar(toolbar);
ActionBar supportActionBar = getSupportActionBar();
Asserts.checkNotNull(supportActionBar); <- this line here is marked, 
                                           that the argument might be null

我觉得很奇怪,checkNotNull行由Android Studio标记,该参数可能为null,因为这很明显,因为这就是为什么我要进行此检查。

您知道如何消除此警告吗?

0 个答案:

没有答案
相关问题