5

Edit - this is solved - the issue was solved by setting: "Settings -> Build, Execution, Deployment - Java Compiler -> Project Bytecode Version : 9"

I'm following the example/tutorial at https://www.logicbig.com/tutorials/core-java-tutorial/modules/getting-started-in-intellij.html

This is NOT a maven project. I have set the source level to 9 in the project structure eg

enter image description here

I have set the project level to 9:

enter image description here

I am getting "Error:(3, 4) java: modules are not supported in -source 8 (use -source 9 or higher to enable modules)" error when trying to build/run the project's main class.

And yes I have seen Intellij IDEA 2018.1 Jdk10 cannot run test which is unanswered.

I have just updated Intellij to 2019.2.4 but the issue remains. I am using SDK 11. How can this be fixed? Thanks.

Edit: the Run/Debug configuration options:

enter image description here

Edit: the error:

enter image description here

Edit: the platform SDK:

enter image description here

Edit: the dependencies panel:

enter image description here

FWIW, the contents of the iml files show language level 9:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module" module-name="common.widgets" />
  </component>
</module>
General Grievance
  • 4,555
  • 31
  • 31
  • 45
JL_SO
  • 1,742
  • 1
  • 25
  • 38
  • Check the configuration that is used for building / running. You should have an "edit configuration" button somewhere on the top bar near the run button. Check if the SDK and parameters used there are ok. – Michal Trojanowski Nov 04 '19 at 13:18
  • Thanks but (under the "Application" dropdown on the LHS pane) there's no SDK option; there is a JRE option and it's set to "Default (11 - SDK of 'data.widget' module). – JL_SO Nov 04 '19 at 13:23
  • Where do you see that error? – Andreas Nov 04 '19 at 13:25
  • In the Messages pane at the bottom of the screen. – JL_SO Nov 04 '19 at 13:27
  • Can you check the Dependencies tab in "Project Structure > Modules"? You can set the module SDK there. – Michal Trojanowski Nov 04 '19 at 13:37
  • The Dependencies says the Module SDK is the Project SDK (11). I will paste a screenshot to the question. – JL_SO Nov 04 '19 at 13:39
  • That's a bummer :( Have you tried to restart with invalidating the cache? I have found this option to help in some weird scenarios. Also are you able to compile the project from the command line? Just to be sure it's an IntelliJ issue. – Michal Trojanowski Nov 04 '19 at 13:42
  • Let me try that now...although I had to restart when I upgraded Intellij.. – JL_SO Nov 04 '19 at 13:45
  • Sorry, no dice...Invalidated and restarted but still, getting the same error. – JL_SO Nov 04 '19 at 13:47

2 Answers2

9

This is solved - the issue was solved by setting: "Settings -> Build, Execution, Deployment - Java Compiler -> Project Bytecode Version : 9"

Thanks to all who gave their time to try to help.

JL_SO
  • 1,742
  • 1
  • 25
  • 38
0

Set SDK

I think you must be setting SDK under Platform Setting in project structure

enter image description here

Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
  • No, I have 11 there (as well as 8). I append/paste the screenshot to the question. – JL_SO Nov 04 '19 at 13:31
  • No! you haven't put snapshot of SDK. what you have shared is project settings – Vinay Prajapati Nov 04 '19 at 13:33
  • Also, can you do a java -version on your intellij terminal? – Vinay Prajapati Nov 04 '19 at 13:33
  • Sorry, I misunderstood your statement. In any case, I think you can see that I have set everything everywhere in Intellij at least to either 9 or 11. But as for java -version in the Terminal window in intellij, that reports version 8: `$ java -version openjdk version "1.8.0_222"...` – JL_SO Nov 04 '19 at 13:37
  • Can you change terminal version to 11 ? I know this shouldn't be the case but just to see if it works – Vinay Prajapati Nov 04 '19 at 13:38
  • Hi Vinay, I understand where you're coming from but I'm at work and we use Java 8; I really don't want to start messing with my Java version on my linux terminal by changing symlinks and environment variables. And in any case I can use Java 9 language features without getting red highlighting (syntax errors/unrecognized keywords such as "module", "requires" and "exports") so I think this should not be the cause. – JL_SO Nov 04 '19 at 13:44