0

I have downloaded Java code from GitHub and am trying to configure or build my changes into a Java package. But I'm getting the below error. I'm not sure what version of Java I need to use to build this project. Any pointers or suggestions would be really helpful.

error: cannot access Copier
import com.example.records.core.Copier;
                                    ^
  bad class file: /home/user957/.gradle/caches/modules-2/files-2.1/com.example.streaming/streaming-core/v1.36.1/758f1477d776e3273c5397d2d5d7e19b5fa46326/streaming-core-v1.36.1-sdk.jar(/com/example/records/core/Copier.class)
    class file has wrong version 62.0, should be 57.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

mySystem JDK version

java -version
openjdk version "18.0.2.1" 2022-08-18
OpenJDK Runtime Environment Temurin-18.0.2.1+1 (build 18.0.2.1+1)
OpenJDK 64-Bit Server VM Temurin-18.0.2.1+1 (build 18.0.2.1+1, mixed mode, sharing)
Shaitender Singh
  • 2,157
  • 5
  • 22
  • 35
  • The expected class file version (57.0) hints at Java 13, the path in the error message hints at using Gradle. Does your `build.gradle` contain a statement like `languageVersion = JavaLanguageVersion.of(13)`? – Thomas Kläger Feb 02 '23 at 07:10
  • @ThomasKläger java.sourceCompatibility = JavaVersion.VERSION_11 // it uses Java 11 java.targetCompatibility = JavaVersion.VERSION_11 – Shaitender Singh Feb 02 '23 at 08:16
  • 1
    At least one of your dependencies (com.example.streaming:streaming-core:v1.36.1) has been compiled for Java 18 (class file version 62). You will need to find a version of that dependency that is compiled for the Java version that your project uses. – Thomas Kläger Feb 02 '23 at 08:31
  • @ThomasKläger issue has been resolved bu configuring java 18 and setting gradle java 18 version, thank you for your help – Shaitender Singh Feb 04 '23 at 06:53

2 Answers2

0

Try JDK version 1.9 or higher. If class files has version 62.0,then least JDK 9 installed on system to be able to compile them

Dev
  • 120
  • 6
0

I solved this problem, by just reinstalling my JDK. If you're using IntelliJ, just head to the project settings and click download in the JDK dropdown menu.

I also solved this problem on my Ubuntu 20.04 machine by running sudo apt install openjdk-13-jdk, which installs the jdk and sudo update-alternatives --config java, which updates the index of the newest jdk (i think).

If I understood you wrongly with the version needed, just adjust the number behind openjdk- to whatever version you need.

All versions to their corresponding class file versions

Z-100
  • 518
  • 3
  • 19