I have a pretty simple project and the specific line in question is the following:
static final Locale defaultLocale = Locale.of("en", "US");
And vscode gives the following code
The method of(String, String) is undefined for the type LocaleJava(67108964)
Its worth mentioning that i can compile this code with gradle, now i thought maybe its a cache thing so i decided to switch to maven instead and i got the same error.
Any ideas? this error is driving me crazy.
Other editors like Intellij dont give this error
3
Answers
Probably you have some additional libraries or custom configurations in Gradle and IntelliJ that are not picked up by VS Code. Try
or using Locale.Builder:
Java 19+
The convenient static factory methods
Locale.of
were added to Java 19. You appear to be compiling for an earlier version of Java.By the way, if using Visual Studio Code, consider: Introducing the Oracle Java Platform Extension for Visual Studio Code
this method was added in Java19. So if your Java version is lower than it, it may not work. You can do this by installing the new version. Or use the constructor to see if the problem can be solved. It’s like this
Locale locale=new Locale("en","US");