简体   繁体   English

Android Studio:List.of() '调用需要 API 级别...'

[英]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.

相关问题 Android studio:调用需要API Level 16错误 - Android studio : call requires API Level 16 error BigDecimal调用需要API级别Android 24 - BigDecimal call requires API level 24 Android 如何在Android Studio中为消息“调用要求API级别21(当前最小值为16)”启用lint错误? - How to enable lint error in Android Studio for message “Call requires API level 21 (current min is 16)”? 如何使用Android Activity修复“Call required API level 11”? - How to fix “Call requires API level 11” with Android Activity? Android Studio:列出需要SDK级别高于项目最低级别的所有调用 - Android Studio: List all calls which requires SDK level above the project minimum level android - 调用需要API级别9(当前最小值为8):android.os.StrictMode #setThreadPolicy - android - Call requires API level 9 (current min is 8): android.os.StrictMode#setThreadPolicy Android Studio 在尝试使用 Java 1.8 类时提示“Class requires API level 24 (current min is 1)” - Android Studio prompts "Class requires API level 24 (current min is 1)" when trying to use Java 1.8 class 调用需要API级别11(当前最小值为1) - Call requires API level 11 (current min is 1) 调用要求API级别21,当前最小值为8 - Call requires API level 21, current min is 8 呼叫需要API级别21(当前为14) - Call requires API level 21 (current is 14)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM