3

我最近将我的 Android Studio 更新到 3.0。我尝试使用 Preconditions.checkNotNull() 但它显示错误并显示以下消息。

Preconditions.checkNotNull() 只能在同一个库组 (groupId=com.android.support) 中调用。

我搜索了一些其他链接,发现在推出较旧的支持库版本时发生了类似的事情。

AppCompatActivity.onCreate 只能在同一个库组内调用

建议的答案告诉我禁用 lint 警告,但从长远来看,我认为这不是正确的做法。

关于为什么会出现此特定错误的任何解释?

4

2 回答 2

0

请改用androidx

import androidx.core.util.Preconditions;

ref = Preconditions.checkNotNull(anotherRef);
于 2019-07-28T21:36:54.810 回答
0

您可以使用内联函数:

requireNotNull

这不会显示类似的警告Preconditions.checkNotNull(ref)

于 2021-06-21T03:41:50.850 回答