[英]Android Studio: List.of() 'Call requires API level...'
I'm trying to use the List.of()
method in one of my Android Studio projects but I'm running into this lint error when writing it:我正在尝试在我的 Android Studio 项目之一中使用
List.of()
方法,但在编写它时遇到了这个 lint 错误:
Call requires API level 30(current min is 21):`java.util.List#of`
Note: I have already found a new solution that I haven't seen in other answers regarding this topic so I'm going to post it below to let others know.注意:我已经找到了一个新的解决方案,我在关于这个主题的其他答案中没有看到过,所以我将把它发布在下面让其他人知道。
I solved this error by adding the following annotation on top of the method that calls the List.of()
method:我通过在调用
List.of()
方法的方法顶部添加以下注释来解决此错误:
@RequiresApi(api = Build.VERSION_CODES.R)
This annotation specifies that the API level must be at least 30(which is what R
represents).此注解指定 API 级别必须至少为 30(这是
R
代表的意思)。 Check the Android Version Codes Page for the appropriate version code for your use case.检查Android 版本代码页面以获取适合您用例的版本代码。
Here is the full method:这是完整的方法:
@RequiresApi(api = Build.VERSION_CODES.R)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.