java: cannot access com.intellij.openapi.actionSystem.DataKey
Answered
I recently upgraded my IntelliJ version from 2018.3 to 2020.3. I now get an error when trying to run code involving data keys:
Editor editor = event.getData(CommonDataKeys.EDITOR);
String highlightedText = editor.getSelectionModel().getSelectedText();
ConsoleViewImpl console = ((ConsoleViewImpl) event.getData(LangDataKeys.CONSOLE_VIEW));
Both of the above code snippets give the following error:
java: cannot access com.intellij.openapi.actionSystem.DataKey
class file for com.intellij.openapi.actionSystem.DataKey not found
This code works fine in 2018.3 but not in 2020.3 and I have been unable to work out why, any help is appreciated.
Please sign in to leave a comment.
Most likely the JAR file(s) of your IJ Platform in Gradle cache are corrupted; and/or try full re-import of your Gradle project.
Class com.intellij.openapi.actionSystem.DataKey definitely exists.
Still the same problem. I have downgraded to IntelliJ 2020.2 and it works as expected on there.
Most probably you're not using Java 11 then, see first entry https://plugins.jetbrains.com/docs/intellij/api-notable-list-2020.html#20203
This problem was with Java version 15
Ok, that explains it.
What is the replacement in Java 15?
You must not use Java version newer than 11 https://plugins.jetbrains.com/docs/intellij/gradle-prerequisites.html#new-project-configuration-screen
Thanks!