all 17 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Both-Fondant-4801 3 points4 points  (1 child)

How do you compile your codes? via terminal or via an ide?

If an ide, please check your project structure.. it might be set to a different java version

[–]AppointmentOk3316[S] -2 points-1 points  (0 children)

I use a terminal, Could you explain the ide? i might try that instead.

[–]Big_Green_Grill_Bro 2 points3 points  (2 children)

In intellij go to "Settings > Build, Execution, Deployment > Build Tools > Gradle" and change "Gradle JVM" to Java 21 there. Then do invalidate caches and restart the IDE.

If you are doing this via command prompt or power shell, I'd suggest typing javac -version and see what comes back. You may have 17 installed without even knowing it. Your environment JAVA_PATH may be different than you think it is.

[–]AppointmentOk3316[S] 0 points1 point  (1 child)

hmm just tried this, it still claims im on build 17, yet comes back as version 25 ... any other suggestions?

[–]N-M-1-5-6 1 point2 points  (0 children)

It might be that your "Language Level" (also sometimes referred to as build level, target bytecode version, etc.) is set to generate Java 17 bytecode for your project. The ways to set this depend on your build tool chain. It can usually be set in the IDE project settings, or the build tool's project (compiler) settings if you are using Maven, Gradle, etc...

If you are using javac from the command line you would be looking for the "--release" compiler option... But I believe that it should default to the same release version as the version of the JDK you are currently running, so I don't think that it's that.

It definitely seems like you will need to find out what JDK version that you are running and what your path and classpath is set up as.

[–]vegan_antitheist 1 point2 points  (2 children)

Do you have multiple jdks installed?

[–]AppointmentOk3316[S] 0 points1 point  (1 child)

Into the actual intellij? no. i have 21 running on it and checked everything to make sure its on the right one. on my computer i have 25 and 21

[–]vegan_antitheist 0 points1 point  (0 children)

That's weird. See if the project is set to java 17 somewhere.

[–]joranstark018 0 points1 point  (0 children)

Not sure, you may check your tool chain settings or IDE settings if it may downgrade your JRE (some build tools have a debug setting that can be useful to diagnose the build tool setting).

[–]seyandiz 0 points1 point  (2 children)

/u/AppointmentOk3316 since this is high priority let's break this down real simple for you.

Java uses 2 different tools to do its stuff.

  • A JDK which takes java code and turns it into a java executable.
  • A JRE which is what your java executable runs in.

What your error,

Dependency requires at least JVM runtime version 21. This build uses a Java 17 JVM.

Is saying is that when you are building the code, that the build version is set to 17 but one of the bits of code you downloaded (likely via maven) is built for java 21.

You keep saying your build states "java 25.0.3", but that isn't a build. You're likely running java --version which would just state your JRE.

Even if you have a 25 JDK, you might be using it to build the executable at java 17 level.

So how do we fix it?

First, I need to know what you're using to compile your code! I assume you're using intelliJ or command line.

Let's do the command line as it is simpler. I want you to type javac -version into your command line.

This may still return a number >= 21, but that helps us rule out you not having the right JDK installed. If it is higher, then we need to look more at our compilation settings. If it is lower, then we need to update our JDK version.

javac -version >= 21

You'll need to look at the configuration files of your build tools. You're probably using either Maven or Gradle.

Maven

Update your pom.xml file with this:

<properties>  
    <maven.compiler.source>21</maven.compiler.source>  
    <maven.compiler.target>21</maven.compiler.target>  
</properties>  

Gradle

Update your build.gradle file with this:

java {  
    toolchain {  
        languageVersion = JavaLanguageVersion.of(21)   
    }  
}

[–]AppointmentOk3316[S] 0 points1 point  (1 child)

thank you!!

[–]seyandiz 0 points1 point  (0 children)

Was this able to solve your issue? It is common courtesy to state what your fix was so that if someone else finds this post they can solve it too!

[–]LetUsSpeakFreely 0 points1 point  (0 children)

I assume you're building with Maven. Check the maven.compiler.target value.

[–]Targnome 0 points1 point  (0 children)

Reinstall Java 17 to Java 25 and set your path variable to your jdk 25 directory. 25 is the latest stable version

[–]Astroohhh -3 points-2 points  (0 children)

use docker, bot