I have some Java code that compiles on my Mac, but fails to compile on my Ubuntu machine. Specifically, when using the static of method of List, I get the error:
error: cannot find symbol
List<String> list2 = List.of("cat", "dog");
^
symbol: method of(String,String)
location: interface List
1 error
I thought perhaps this was an issue with the Java version. Sure enough, it was using only Java 8. However, I subsequently upgraded my Ubuntu machine to use Java 11 using OpenJDK, but I still get the same issue.
The output I get from running java -version on the Ubuntu machine is:
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment (build 11.0.1+13-Ubuntu-3ubuntu116.04ppa1)
OpenJDK 64-Bit Server VM (build 11.0.1+13-Ubuntu-3ubuntu116.04ppa1, mixed mode, sharing)
The output I get from running java -version on the Mac machine is:
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
For compilation, I am using Gradle version 5.2.1. I am using the Gradle wrapper, so both machines are using the same version of Gradle.
Here is the file that does not compile properly.
package mypackage;
import java.util.List;
import java.util.ArrayList;
public class App {
public static void main(String[] args) {
// No errors on both MacOS and Ubuntu
List<String> list1 = new ArrayList<>();
list1.add("cat");
System.out.println(list1);
// Fails to compile on Ubuntu
List<String> list2 = List.of("cat", "dog");
System.out.println(list2);
}
}
List.of() was introduced in Java 9. This indicates that your update from Java 8 to Java 11 wasn't successful.
Run ./gradlew -v to see which version of Java is resolved by Gradle:
------------------------------------------------------------
Gradle 5.3.1
------------------------------------------------------------
Build time: 2019-03-28 09:09:23 UTC
Revision: f2fae6ba563cfb772c8bc35d31e43c59a5b620c3
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Linux 4.15.0-47-generic amd64
Make sure you aren't using Gradle daemon started on Java 8 before updating to Java 11 and in build.gradle force Java 11 compatibility:
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Related
I wanted to use my JDK 10 in my Android Studio. I went to Files > Project Structure and specified my JDK location:
C:\Program Files\Java\jdk-10
After I clicked 'OK', it showed me a Gradle sync failed message with an error:
Could not determine Java version using executable C:\Program Files\Java\jdk-10\bin\java.exe.
I've set the JAVA_HOME variable to my jdk and jre folder, and the path variable to C:\ProgramData\Oracle\Java\javapath but the problem still occurs.
I can also find the Java version with the command:
"C:\Program Files\Java\jdk-10\bin\java.exe" -version
which gives me the correct version:
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
Screenshot:
Versions:
OS: Windows 10 64-bit
Android Studio Version: 3.1.0.16
JDK Version: 10
it happen in android studio 3.2.0 when your import your project to new android studio you must use this build gradle or newer
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
}
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 2 years ago.
Before you read my question, you should know that it's not a duplicate to all other similar questions on Stackoverflow that I already read!
I've developed (and built and compiled) a Hadoop program on Windows 10 (development machine) using Eclipse. The program reads WARC files and rewrite them in JSON format. It uses these classes to override the Writable format:
WarcFileInputFormat.java
WarcFileRecordReader.java
WritableWarcRecord.java
I added hadoop- 2.6.0 jars files to my project.
This is the java version of development machine:
$java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
I tested my code on Ubuntu 14 machine (testing machine) and it just worked perfectly. this machine has hadoop- 2.6.0:
Hadoop 2.6.0
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r e3496499ecb8d220fba99dc5ed4c99c8f9e33bb1
Compiled by jenkins on 2014-11-13T21:10Z
Compiled with protoc 2.5.0
From source with checksum 18e43357c8f927c0695f1e9522859d6a
This command was run using /home/username/hadoop-2.6.0/share/hadoop/common/hadoop-common-2.6.0.jar
This is the java version of testing machine:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
I moved to a CentOS oracle server and ran my program. This server has the same java version as my development machine:
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
and it had this Hadoop version:
Hadoop 2.6.0-cdh5.13.1
Subversion http://github.com/cloudera/hadoop -r 0061e3eb8ab164e415630bca11d299a7c2ec74fd
Compiled by jenkins on 2017-11-09T16:37Z
Compiled with protoc 2.5.0
From source with checksum 16d5272b34af2d8a4b4b7ee8f7c4cbe
This command was run using /opt/cloudera/parcels/CDH-5.13.1-1.cdh5.13.1.p0.2/jars/hadoop-common-2.6.0-cdh5.13.1.jar
On this server I got the following error for each job:
18/02/23 11:59:45 INFO mapreduce.Job: Task Id : attempt_1517308433710_0012_m_000003_0, Status : FAILED
Error: data/warc/WarcFileInputFormat : Unsupported major.minor version 52.0
Here are the things I tried and they didn't work:
Adding the WARC readers' classes to my project as classes not as a jar to build them using the correct java version.
Changing Hadoop jar files version from hadoop- 2.6.0 to hadoop- 2.6.0-cdh5.13.1
Using mapred instead of mapreduce as the reader classes are using mapred
I'm not sure what exactly causes this issue especially that it points to the class WarcFileInputFormat.java that I didn't write but added to my project from the link I provided above. What surprised me is that the program worked perfectly on Ubuntu machine that has a lower java version, but didn't work on the CentOS server that has the same java version as the Windows development machine!
Any hints?
The problem was that Cloudera uses a lower version of JAVA:
/usr/java/jdk1.7.0_67-cloudera/bin/java
I had the same error message as yours, it occurred to me when I was implementing a Hive UDF.
I saw your answer and I tried Java 1.7 instead of 1.8 to build the JAR file of the UDF, and it worked.
I was using Cloudera Quickstart VM and it has JAVA_HOME set to Java 1.7
Everyone!
I have a java program with jar libraries that works on the following JDK version:
java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
I need to make it compile on a supercomputer that works on the following JDK version:
java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
As you can see they all have the same JDK which is JDK 8. However, when compiling using:
javac myFile.java
The following error appears:
class file has wrong version 51.0, should be 48.0
It seems that the compiling is done on another JDK (other than 8). Can anyone please help me solve this problem?
Kindest Regards!
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
J2SE 8=52,
J2SE 7=51,
J2SE 6.0=50,
J2SE 5.0=49,
JDK 1.4=48,
JDK 1.3=47,
JDK 1.2=46,
JDK 1.1=45
First Rule: Java version must be same on your local pc and server. Otherwise this kind of unwanted problem may arise.
For more checking, You can check
java --version
javac --version
It will make clarify of jdk and jre version mismatch. If it shows various version, then uninstall other versions and build your project and deploy on server.
Another answer is similar to your problem is here: Cannot compile Java code - "class file has wrong version 52.0, should be 48.0"
Resource Link:
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
$ gradle -version
Gradle 2.14
------------------------------------------------------------
Build time: 2016-06-14 07:16:37 UTC
Revision: cba5fea19f1e0c6a00cc904828a6ec4e11739abc
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_80 (Oracle Corporation 24.80-b11)
OS: Mac OS X 10.11.5 x86_64
I get this error when using Intellij to build a Gradle project
anyone know what's up with that? Should I use Java 8 instead of Java 7?
When trying to use GraphicsBuilder, I get a java.lang.NoClassDefFoundError for groovy.swing.factory.BindProxyFactory.
This is my environment:
% java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
% groovy --version
Groovy Version: 1.5.7 JVM: 1.6.0_10
% ls ~/.groovy/lib/graphicsbuilder*
graphicsbuilder-0.6.1.jar
...
And this is what I try to do:
% groovysh
Groovy Shell (1.5.7, JVM: 1.6.0_10)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------
groovy:000> import groovy.swing.SwingBuilder
groovy:000> import groovy.swing.j2d.GraphicsBuilder
groovy:000> import groovy.swing.j2d.GraphicsPanel
groovy:000> def gb = new GraphicsBuilder()
ERROR java.lang.NoClassDefFoundError: groovy.swing.factory.BindProxyFactory
at groovysh_evaluate.run (groovysh_evaluate:5)
...
Where is BindProxyFactoryBean?
It's in the Groovy 1.6 builds, not the 1.5.7 builds. Apparently GfxBuilder 6.1 was built against the Groovy 1.6 codebase.
Yes, that is correct. Groovy 1.6.x is required for GfxBuilder 6.1 and onwards.