Why cant I import java.time.ZonedDateTime into Eclipse? - java

I have Java 8 installed and worked in my Eclipse project as far as I can tell. This line does not work though:
import java.time.ZonedDateTime;
I also can't seem to get:
import java.time;
to work either.
It tells me this line cannot be resolved. I thought this was part of standard Java 8 library? Is there a place I am meant to go to download the JAR for the ZonedDateTime class or something?
I'm making AWS Lambda functions in eclipse, if that matters.
I went into the properties for the project and noted the compiler compliance level was set to 1.6, so I changed this to 1.8. now I get a warning that says:
When selecting 1.8 compliance, make sure to have a compatible JRE installed and activated (currently 1.6).
When I go to the link it provides for installed JREs i only see 1.6. How do I get and install the 1.8 JRE so that it will appear from this list as selectable?

All those Classes are only available since java 8,
make sure your project have in the JRE System library in the eclipse project the right version

Go to Window > Prefrences > Java > Installed JREs
Select your JDK 8 directory.
Also go to project -> Properties -> Java Build Path -> select JRE System Library click Edit and select JDK or JRE after then click Java Compiler

Related

Incompatible Java Versions for WindowBuilder

I Installed WindowBuilder on Eclipse to create a Graphic User Interface for a program. When I go to the 'Design' tab the following error appears:
Eclipse is running under 1.8, but this Java project has a 10 Java
compliance level, so WindowBuilder will not be able to load classes
from this project. Use a lower level of Java for the project, or run
Eclipse using a newer Java version.
I currently have Installed Java 8 (Update 171), and Oxygen.3a (4.7.3a) (Eclipse Version). I had previously downloaded Java 10, but I read that there's a bug where WindowBuilder doesn't work on that version, and that it is recommened the Version 8, which is the one I downloaded and installed (after uninstalling Version 10). But the problem's still there.
What could I do to solve this? Thank you.
Just change the compliance level of the project from 10 to 1.8, rebuild and the Design tab should work:
To change the project's compliance level:
Select the project's node in Project Explorer, right-click and select Properties.
Select Java Compiler from the column on the left.
Uncheck Use Compliance from execution environment...
Select 1.8 from the drop list for Compiler compliance level. (Presumably its current value is 10.)
Click the Apply and Close button.
Rebuild the project using 1.8 compliance.
The Design tab should work fine now.
As a separate issue, since you have uninstalled Java 10 you should also remove it from your Installed JREs if you haven't done that already:
Windows > Preferences > Java > Installed JREs
Select the entry for JDK 10 and click the Remove button.
If the JDK 10 entry was checked when you removed it you will be forced to check another JRE definition.
Click the Apply and Close button.
WB 1.9.1 has solved the issue:
https://www.eclipse.org/windowbuilder/download.php
Just change the compliance level of the project from the current to 1.8, rebuild and the Design tab should work:
It works for me

Using a JAR package that uses a different Java version in eclipse

I have Java 8 and I've been trying to use a JAR package that uses JRE 6.
In 'Create a Java Project' I used the 'Use a project specific JRE' and also
created a run configuration but when I try to set the alternate JRE to 6, the 'run' button gets blocked out. Are they not compatible or am I missing a step? I've also tried changing the PATH destination, though I'm not sure if that is even relevant to my problem.
EDIT: I am using a JAR package from an online source that is Java 6 compatible and am trying to integrate it into Eclipse Mars with Java 8 installed.
A few items to check, under Project settings: (most of these can be set workspace-wide as well)
Java Build Path > Libraries. Replace JRE System Library with a jdk6 execution environment or alternate JRE
Java Compiler > JDK compliance. Set to 1.6
System:
Check Installed JREs and Execution environments. Make sure a JRE is linked to the Execution Environment for JavaSE-1.6 (with the checkbox).
Did you try just adding the external JAR to the project? Most (non-executable) JARs that were originally made for older versions of java should still work today.
To add an external JAR: right-click on your project in the package explorer and go to Build Path >> Add External Archives... then select your JAR from there. Be sure to leave the project set up for JRE8.
The reason that your run button is blocked out when you switched to JRE6 was because Eclipse detected that it was not installed and therefore cannot run it as JRE6.

Java for Eclipse compilation JRE issue

I use Mac OS, 10.6 and after recovering my back-up data, Eclipse stopped working. It gives me the following errors:
The container 'JRE System Library [JavaSE-1.6]' references non existing library '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar'
Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'Proba'
I attempted to install again Java Development Kit (Help -> Install new software), and Eclipse actually installed it, but when I go to (Eclipse -> Preferences -> Java -> Installed JREs), I get error "Installed JRE location no longer exists. JRE will be removed. Reason: JRE removed", and installed JREs window is indeed empty. And the Java code still doesn't compile.
Solution: Go to: Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment and choose the JAVA SE 6 package (possibly JAVA SE 7 could work) and then choose the compatible JREs in the right-hand side.
Reload Eclipse.
Two possibilities:
1. Update the Installed JRE
(Depending on the issue, one of the following will do)
Remove and Recreate the Installed JREs instance for the failing JVM.
Eclipse -> Preferences -> Java -> Installed JRE
Install a new version of Java. (You can get it here), then Create a new instance using Eclipse's 'Installed JREs'. Set it as the default.
Eclipse -> Preferences -> Java -> Installed JRE
(As you noted)
2. Update the Execution Environment such that it is compatible with the JRE.
Go to Eclipse -> Preferences -> Java -> Installed JREs -> Execution Environment and select a compatible env.
Here is how to fix things up:
Some versions in Mac like Lion does not come with a JDK; you can go and download one directly from http://connect.apple.com. Yes you need to sign up and login with your apple id. The download column is over on the right; and you should be able to find your way.
The jdk is installed into a different location. This will result in IDEs (such as Eclipse) being unable to locate source code and javadocs.
At the time of writing the JDK ended up here: /Library/Java/JavaVirtualMachines/1.6.0_31-b04-415.jdk/Contents/Home
Please go ahead and have a look to confirm where your JDK ended up; this will no doubt change over time.
Open up eclipse preferences and go to Java --> Installed JREs page
Rather than use the "JVM Contents (MacOS X Default) we will need to use the above JDK location
At the time of writing the Search button was not aware of the new JDK location; we we will need to click on the Add button and hunt it down ourselves.
From the Add JRE wizard choose "MacOS X VM" for the JRE Type
For the JRE Definition Page we need to fill in the following:
JRE Home:/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
The other fields will now auto fill, with the default JRE name being "Home". You can quickly correct this to something more meaningful:
JRE name:System JDK
Finish the wizard and return to the Installed JREs page
Choose "System JDK" from the list
You can now developer normally with javadocs correctly shown for for the base classes like java.lang.String, source code correctly shown when debugging.
The error above is simply saying that the Eclipse variable your JREs/JDKs have moved and the relevant variables defined within Eclipse point to locations that no longer exist now.
All you have to do is to point those variables to the new location, and the methods suggested above are good to go.
4 Possible Alternatives:
Re-configure the libs.
Update the JRE.
Update the Execution Environment.
Check for MAC Updates. //Some versions of Mac does not have support for JDK by default. But you can re-configure this to solve your issue by using JDK rather than Mac Default variables.
One more thing which you can try is, to restore the Eclipse to Default state, i.e., re-install the version of Eclipse which you are using.(By the way, this worked for me, when I had a similar issue).
I had the same problem on Spring Tool Suite(v 3.7.2) and took the following steps to resolve this :
cd $JAVA_HOME/jre (On a mac)
pwd (This will give the location of JRE directory)
STS > Preferences > Installed JREs > Add the location of the JRE
I had this happen after my system Java updated itself. I restarted Eclipse, it did a build, and the error went away.

Setup eclipse java SE-1.7

I wanted to start learning java but Eclipse is giving me some trouble.
First of all I'm a beginner with Java with little to no knowledge about it. I want to use 'JavaSe-1.7'. I have no clear reason to use it besides using the latest version. After downloading Eclipse (Eclipse IDE for Java Developers) I created a new Java project and selected 'use an execution eviorment JRE : JavaSE-1.7'. This directly popped the notification saying 'The default compiler compliance level for the current workspace is 1.6. The new project will use a project specific compiler compliance level of 1.7.'. I finished creating the project and started following some tutorials.
However I noticed directly I have 2 errors which dont explain anything or have a source. I ignored it and started typing and tried to import 'java.io.console' however it said 'The import java.io cannot be resolved' and I have no idea what is the cause of it neither how to fix this.
Would like some instructions into the right direction.
Thanks in advance
Check your Eclipse preferences: Java -> Installed JREs. The one that you're using should be marked and it should be a JDK not just a JRE.
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one (from an installed JDK).
You may not have your JDK/JRE set up correctly.
Check the following:
Did you install a JDK or just the JSE? The JDK is needed to compile .java files to .class files. Without it, you can only run java programs, not develop them. If not, download and install it from Oracle website.
Check in Eclipse, if you have the JRE installed there as well. You just need to specify the path to the installation. You can reach this screen via the "Window->Prefrences" menu. see this screenshot:
The message you receive about project specific compiler compliance level is not a problem, it just means that your workspace is set up to comply to java 1.6 but your project will comply to java 1.7 standards. Also, Java 7 in general is no problem whatsoever.
Paths may differ, especially if you're not running a *nix OS. Just point the location to where you installed your JDK.

Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties

Did anybody have similar problem with this, I import android project and I get
errors like
[2011-10-03 17:20:09 - Screen] Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
[2011-10-03 17:21:55 - App] Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
[2011-10-03 17:21:59 - App] Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
I got errors to delete all #Override above functions. I have Windows 7 x64, jvm7 x64. Does anyone have clue what is wrong ?( I done Android Tools -> Fix Project Properties but didn;t help )
That isn't the problem, Jack. Android SDK isn't x64, but works ok with x64 jvm (and x64 eclipse IDE).
As helios said, you must set project compatibility to Java 5.0 or Java 6.0.
To do that, 2 options:
Right-click on your project and select "Android Tools -> Fix
Project Properties" (if this din't work, try second option)
Right-click on your project and select "Properties -> Java
Compiler", check "Enable project specific settings" and select
1.5 or 1.6 from "Compiler compliance settings" select box.
Go to the project folder and right click on it -> properties -> check off the read only box and click ok
Right-click on your project and select "Android Tools -> Fix Project Properties"
Right-click on your project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.5 or 1.6 from "Compiler compliance settings" select box. (try all the levels one by one just in case)
Under Window -> Preferences -> Java -> Compiler, set Compiler compliance level to 1.6 or 1.5.
Hopefully it will settle the problem.
I would recommend using x86 version of jvm. When I first got my new laptop (x64), I wanted to go x64 all the way (jvm, jdk, jre, eclipse, etc..). But once I finished setting everything up I realized that the Android SDK wasn't x64, so I had issues. Go back to x86 jvm and you should be ok.
EDIT: 11/14/13
I've seen some recent activity and figured I would elaborate a little more.
I did not say it would not work with x64, I just recommended using x86.
Here is a good post on the advantages / disadvantages of x64 JDK. Benefits of 64bit Java platform
Thought process: To what end? Why am I trying to using 64 bit JDK? Just because I have a 64-bit OS? Do I need any of the features of 64-bit JDK? Are there any extra features in the 64-bit JDK?! Why won't this s*** play nice together!? F*** it I'm going 32-bit.
Doing Project -> Clean... fixed it for me.
My eclipse had stopped working so I cleaned workspace directory and after I run eclipse when I import the project I had this problem. Other solutions suggested here didn't work.
For most of the people still receiving the error after fixing project properties, you probably installed Java 7 SDK when setting up your environment, but it is not currently supported for Android development.
As the error message sais, you should have installed Java 5.0 or 6.0, but Java 7 was found.
If you fix project properties without first installing Java 5 or 6, you will see the same error again.
So first, ensure you have Java SDK 5 or 6 installed, or install it.
Check your environment variable (JAVA_HOME) is pointing to SDK 5/6.
And then:
Check that Eclipse is using SDK 5/6 by default (Window => Prefs. => Java => Compiler
Disable Project Specific Settings (Project Properties => Java Compiler)
Fix Project Properties
OR
Leave Eclipse using JDK 7 by default.
Enable Project Specific Settings (Project Properties => Java Compiler)
Select Compiler Compliance 1.5 or 1.6 (Project Properties => Java Compiler)
I agree with BMSAndroidDroid and Flo-Scheild-Bobby. I was doing a tutorial called DailyQuote and had used the Cordova library. I then changed my OS from Windows to Ubuntu and tried to import projects into Eclipse, (I'm using Eclipse Juno 64-bit, on Ubuntu 12.04 64-bit, Oracle JDK 7. I also installed the Ubuntu 32-bit libs- so no issues with 64 and 32bit), and got the same issue.
As suggested by Flo-Scheild-Bobby, open configure build path and add the jar(s) again that you added before. Then remove the old jar link(s) and thats it.
I fixed this problem employing the two procedures of :
In Eclipse->'Project' menu -> 'Java Compiler' -> set 'Compiler compliance level' = 1.6
check on 'Use default compliance settings'
Set 'Generated .class compatibility' = 1.6
Set 'Source compatibilty' = 1.6
Then go to 'Windows' menu --> 'Preferences' -->'Java' , expand 'Java' --> 'Compiler' -->Set 'Compiler compliance level' = 1.6
Hint: Source compatibility must be equal to or less than compliance level.
I would suggest that u check for the jar files are properly included in your projects. There are possibility that in absence of jar files, the project will not be compiled
As BMSAndroidDroid said, this problem may be caused by a wrong build path configuration.
If you included some libraries to your build path, then move the libraries, the build path will conserve the wrong references, will not found the libraries during compilation and you will get an error.
To fix it, right click on your project folder > build path > configure build path
Then take a look to the library tab, and remove the old libraries.
In my case a switch from openjdk7 to openjdk6 helped. Afterwards I changed the compliance level to 1.6 and all compiled fine.
i come across this problem cause my debug.keystore is expired, so i deleted the debug.keystore under .android folder, and the eclipse will regenerate a new debug.keystore, then i fixed th
Following worked for me
Enable project-specific settings and set the compliance level to 1.6
How can you do that?
In your Eclipse Package Explorer 3rd click on your project and select properties. Properties Window will open. Select Java Compiler on the left panel of the window. Now Enable project specific settings and set the Complier compliance level to 1.6. Select Apply and then OK.

Categories

Resources