flyingfishcattle
flyingfishcattle

Reputation: 2153

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:

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.

Upvotes: 0

Views: 1825

Answers (1)

flyingfishcattle
flyingfishcattle

Reputation: 2153

I solved this error by adding the following annotation on top of the method that calls the List.of() method:

@RequiresApi(api = Build.VERSION_CODES.R)

This annotation specifies that the API level must be at least 30(which is what R represents). Check the Android Version Codes Page for the appropriate version code for your use case.

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);
    ...
}

Upvotes: 0

Related Questions