Well I just started working on codenameone I have a quite decent experience with Java. My code is all good, got no problems although while compiling I get this: error: package java.time does not exist import java.time.LocalDate;
Yes I know LocalDate was introduced in Java8 so my netbeans is set on Java8 also my project.
Note that I'm using Lambda Expresions and streams in the project without any problem.
What can cause this?
Update: This bug is not only with my machine, tested on several machines that run Java 8 correctly (java.time is seen) with JavaFX application or simple Java applications still have same bug with Codenameone projects.
In NetBeans you need to choose Java8 in order to use Java8 features. It is not enough to only have Java8 installed.
Finally I came to a fair answer. Codenameone is not compatible with all java 8 features. See here for more details.
Find Java Dependencies -> JDK 1.8 (Default) -> rt.jar at your Projects frame in Netbeans. You should see java.time package under rt.jar. If not, there is something wrong with your Netbeans or JDK installation.
You can also check Tools -> Java Platform to make sure Java 8 is correctly configured with Netbeans.
Related
I'm developing for a project which is compiled for Java 7.
In this project I use OkHttpClient v3.12.13, which is compatible for Java 7 (as stated here). However these lines produces an error in the Eclipse editor:
private static final OkHttpClient GLOBAL_OK_HTTP_CLIENT = new OkHttpClient.Builder()
.readTimeout(10, TimeUnit.SECONDS)
.build();
The error is this:
The type java.time.Duration cannot be resolved. It is indirectly referenced from required .class files
This error is only shown by the editor. Indeed, when I compile my project using CLI (outside Eclipse) I don't get any error for that implicit reference to the java.time package.
I'm aware that in Java 7 there is no java.time package. Indeed, I'm not using it in my code, it's just implicitly referenced by the OkHttp library (as the error message says).
Is there a way to fix this error on Eclipse?
This is how I configured compiler compliance on Eclipse:
Note that I can't upgrade to newer Java versions.
The java.time classes are built into to Java 8 and later. You are deploying your app to Java 7. That version of Java lacks the java.time.Duration class invoked by your code calling a library.
You claim that library supports Java 7. If that is true, the library must have a switch to avoid using classes not available in Java 7.
You have improperly configured your IDE to allow programming in a later version of than the version on which you deploy. That is a problem you should fix. If deploying on Java 7, then compile for Java 7. See Question, how do I get eclipse to use a different compiler version for Java?.
Of course, the best solution is to migrate to a modern version of Java. Java 7 reached end-of-life in 2015-04. I highly recommend moving to a long-term support (LTS) version. Currently that would be Java 8 and Java 11.
If it were your own code using the java.time classes, I would suggest adding the ThreeTen-Backport library to your project. That library provides most of the java.time functionality with nearly identical API for use with Java 6 and Java 7. But I am guessing that would not satisfy your library in question, though you might want to verify.
Same issue I was facing, Changing the version of selenium in pom.xml worked for me. Changed version from 4.1.0 to 3.141.59
I am a beginner programmer and now I want to start GUI applications in java.(as I previously worked on java too). I started reading some books on FX but its not compiling on JDK11 .. Do I need to use jdk8 or is there any way i can do it on jdk11 too?
JavaFX has become unbundled from JDK11 (both Oracle's official JDK and OpenJDK). In order to use JavaFX with JDK11, you'll have to download the standalone JavaFX11 runtime.
I'm trying to use a library that uses java 8 in my android project. I cannot find a way to make this work. I've tried to use retro lambda but it has not helped. I keep getting the error: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version(0034.0000)
I've researched this and learned it's because there is java 8 syntax in the included library. I've been compiling with java 8 sdk and am using android studio 08.2. Help!
The library is:https://github.com/robrua/Orianna
Solution 1
Wait for android to support Java8.
Solution 2
Use an earlier version of the library that isn't Java8 and/or ask the developer of the library to provide one/ the last Java6 (or Java7 for kitcat upwards) library.
Solution 3
This is some kind of hack and I haven't tested or even used it!
Use retrolambda to backport the Java8-bytecode to Java6. On the homepage of retrolambda you find some documentation about it.
Downloads of retrolambda are here.
Probably you will have to unzip the library jar to a folder and the run a command like the following:
java -Dretrolambda.inputDir=<extracted_classfiles>
-Dretrolambda.classpath=<extracted_classfiles>
-Dretrolambda.bytecodeVersion=50
-javaagent:retrolambda.jar
-jar retrolambda.jar
Maybe you have to extend the classpath depending on the dependencies of the library.
Then you have to copy the resulting jar-file into your android-project's lib folder.
It is also possible to program Java8 for android.
If retrolambda doesn't work maybe you can find another tool to backport Java8-bytecode to Java6-bytecode.
I've run into a pretty weird problem.
I checked out a repo from github in eclipse. It's a gwt project. When I try to compile the project, I got an error:
No source code is available for type java.util.Objects.
There are also some similar errors which all point to the same problem: I use the wrong Java version.
What is weird here is that I do use Java 7 in my project.
I can not post an image here but I do use java7. I added a test class which contains some features in java7, like switch(String), it works fine when I run it as a Java application.
Got a clue? Need help!
Answer: Thanks to sᴜʀᴇsʜ ᴀᴛᴛᴀ, I got it right. I used gwt-2.5.1. Change it to 2.6, it works! Thank you guys.
That's because Eclipse couldn't find the java library.
Please check the project settings and source tab. and make sure that the java sdk was included.
If are you using GWT 2.6 , then below 2.6 versions of GWT doesn't support java7.
Java7 support added in GWT 2.6 version.
Make sure that the GWT version and Java version matching or not.
Just because you have java 7, doesn't mean you have the source for it.
Java code running in GWT is translated to Javascript, so some classes that work on a JVM won't work with GWT
Check the JRE system library in project build path.
Right click on project -> Build Path -> Libraries
Also check for the java compiler compliance level
Right on project -> Properties -> Java Compiler
I'm writing a program with Java7 and JavaFX2, but I'll need to show it to people who only have access to machines with Java 6 installed (with no JavaFX).
Is there any way I can find a solution to this short of asking them to install Java7 and JavaFX2?
Perhaps you can create a self-contained application package by "bundling" your program with Java 7 and JavaFX 2. That way you don't have to worry about what's on or not on your user's machine.
You can read more about self-contained application packaging at http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm.
Theoretically yes, but you have to check if that is conform to the license conditions of Sun/Oracle the owner of JavaFX:
You could sue tools like http://one-jar.sourceforge.net/
They pack all your java into one jar.
Another possibility you could obfuscate your application and include JavaFX.
But this, too might violate the license conditions.
Both solutions might be more work, than the effort off installing JavaFX to the (one)clients computer.
Try JavaFX2 for JavaSE6
On page: http://www.oracle.com/technetwork/java/javafx/downloads/index.html
Download Download JavaFX 2.2.3 for Java SE 6 ...
If you are using Eclipse JDT, you can configure your projects "Java Compiler", by "Enable project specific settings", to "Compiler compliance level" value 1.6. This should produce bytecode in a version suitable for Java 1.6 VM. I suppose, but am not sure, that Eclipse shall also warn you if you use library elements not present in the 1.6 library version; though you can be careful about that with or without warnings. As with the previous solutions, JavaFX you can just package in your application's JAR if the license agreement allows it.