How to fix java language level error in netbeans - java

How can I fix these java language level error which shows:
use -source 7 or higher to enable strings in switch
I am using netbeans as an IDE.

With right mouse click on a project name open pop-up menu and choose "Properties". There will be project properties window opened. Choose category "Sources" and change field "Source/Binary Format":
If you have several JVM versions installed, choose the necessary version under "Build/Compile":

Related

Eclipse IDE's Java Build Path has changed. Which do i choose?

I am trying to follow some tutorials on Selenium, but get stumped at this point.
Right-click on "project" and select Properties.
On the Properties dialog, click on "Java Build Path".
Click on the Libraries tab, and then
Click on "Add External JARs..
The Add External JARS button is grayed out, and disabled.
The dialog shows Modulepath and Classpath.
If I pick either of these, the buttons are enabled.
The question is, which one do I pick?
I am trying to add the selenium WebDriver's into Java Build Path.
Select Classpath for the previous/legacy behavior.
Modulepath is for modular Java 9 applications.
You have to select Java SE 1.8 while creating project.

Eclipse source level problems

Eclipse tells me:
for each statements are available only if source level is 1.5 or greater
what does that mean and how do I solve this? I'm trying to import a program I built with NetBeams which has a GUI. Should I post the full code as well?
Open the Preferences panel and set source level or maybe check Use default compliance settings.
Eclipse's source level is a feature allowing code to be written for older versions of Java, using a limited feature-set. For some reason or another, your project got imported, and the source level was set too low. You need to set it higher.
Go to project properties by right-clicking the project in the explorer at left, and select the "java compiler" pane at the left of the settings window.
Set the compliance level and source compatibility to 1.5 or higher (highest is usually OK, though you may want to stay no higher than 1.7 for now)
On the "Java Build Path" pane,"Libraries " tab, make sure that the JRE system library is at least as high as the source compatibility and source levels you set.

Specified VM install not found: type Standard VM, name jre7

Specified VM install not found: type Standard VM, name jre7
Have you ever encountered this problem in Eclipse while building an ant file? Then this article is for you. Deleting and recreating the workspace is not the solution. There is an easy solution to fix this issue without recreating the workspace.
Right Click on build.xml
Go to "Run As" >> "External Tools Configurations..."
It shall open new window
Go to JRE tab
Select proper JRE if missing (sometimes jre tabs shows error mark on that.)
For more technical details or issue similar to this find my blog here.
In my case it happen as I have changed my JRE.
Solution :
Right click on your ant script > Run as > External tool configurations... > Go to JRE tab > select JRE
Hope this help.
Thanks,
Sagar Vyas
Best answer found at
It happened for me after Un-installing Java and installing new version.
All I have to do is in eclipse open Installed JREs from
Windows --> Preferences --> Java --> Installed JREs
Then Add new JRE information. Details can be found here
This is a preferred way tell projects which JDK container to use, especially true if two or more devs are using the same version controlled eclipse project folder.
Window/Preferences/Java/Installed JREs
List one or more JDKs installed on your computer. Eclipse defaults name to jdk1.X.X_XX you should keep it as is. Never link project build settings directly to use these names.
Window/Preferences/Java/Installed JREs/Execution Environments
List of common jvm environments such as JavaSE-1.6 and JavaSE-1-7 names. Click rows and choose jre instance on the right side panel. These names are common and all team members should already have them in Eclipse installation.
Step 1: This is where you may accidentally have nothing chosen if JREs were uninstalled or names changed in InstalledJREs setting. You may get
Specified vm install not found error dialog.
Step 2: Choose 2nd mouse on build.xml file/Run As/Ant Build... popup menu entry. Click on JRE tab and choose execution environment. This may have obsolete value from the previous jdk values.
Project Properties/Java Build Path/Libraries
Add Library.../JRE System Library/(x)Execution environment
Choose execution environment to be used for this project. Team members may not have exact _XX jdk build but they can use the same version controlled eclipse project settings. Execution environment mapping hides user specific details.
Just had this issue & the solution above does not work, atleast not for me.
Instead I went the solution provided here:http://www.javaworkspace.com/VMNotFound.do
Essentially you go to the directory C:\projects\WORKSPACE.metadata.plugins\org.eclipse.debug.core.launches
In there search for the string of the JDK that that eclipse is moaining about & change it to the name of your installed JDK that you want to use that eclipse knows about.
You can change what JRE the ant bulid file is launched with inside eclipse.
Right click on the ant file in the ant view and select "Run As"->"Ant..." from the context menu.
Then in the launch dialog select the JRE tab. Note the error message at the top if it can't find the JRE that it expects.
Select a JRE that you have installed or manage install a new one. You can also add vm arguments (enable logging or change memory alocation) if you need to in this dialog.
Just delete the below file
"<Your eclipse workspace location>\.metadata\.plugins\org.eclipse.debug.core\.launches\<projectname>.xml.launch"
link to post
The last answer is absolutely correct, however a fast track way is to delete the project reference from eclipse (make sure to keep unchecked delete source) and import your project folder again. This way the project configurations are reset by eclipse using the new jdk.
But a wonderful post it did help me.
After Java update ant build failed and the below steps fixed it .
Right Click on build.xml-Run As-External Tools
Go to JRE tab and check the box to use the JRE same as workspace.
Removed below file and build maven project again, worked for me.
.metadata.plugins\org.eclipse.debug.core.launches\.xml.launch"
(ant file)Run As--> External Tool Configuations,
go to JRE tab and choose JRE

Upgrade a Java 6 Project to Java 7 in Eclipse

I have an old Java 6 Project in Eclipse. To use functionality of Java 7 I would like to switch to Java 7. I am not able to do it :
Goal->No compilation errors in my Java Code . See red underlinded the compilation error when using ZipFile with 2 parameters used for Java 7. The Constructor of ZipFile in Java 6 has one argument. In Java 7 there are 2 arguments:
My Environment in my project:
Compilation Error is:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor ZipFile(String, Charset) is undefined
The constructor ZipFile(String, Charset) is undefined
at ZipCompare.compare(ZipCompare.java:103)
at ZipCompare.main(ZipCompare.java:77)
When I create a new Project from scratch, there are no compilation errors. I compared all settings from my old project and the new one and did not find any differences so far ?
Any help ?
Here are the exact steps in case anyone in the future needs them:
In the Package Explorer window, right-click your project and select "Properties" from the context menu, or go to File > Properties.
In the Properties dialog window, select "Java Build Path" from the left sidebar menu, then click the Libraries tab on the right-hand side.
Select your 'JRE System Library' and click the "Edit..." button. Assuming you have the latest JRE installed, you should be able to change the "Execution environment" there.
If not, go to "Alternate JRE:" and click the "Installed JREs..." button.
Assuming you don't see the one you want listed, click "Add...", ensure "Standard VM" is selected, click "Next", click "Directory" and navigate to your new JRE root folder (i.e., "C:\Program Files\Java\jre1.8.0_20").
Once you click "Finish" and then "OK", you should be able to switch back to "Execution environment" and select the JRE you desire.
Click "Finish" and then select "Java Compiler" from the left sidebar menu. Double check that under JDK Compliance you have "Use compliance from execution environment...." checked.
Now your project should compile and run under the new JDK/JRE.
My messy solution. I don't know if there are sideeffects. So far no:
Rename the old project to XXXXX_OLD
Create new Project XXXXX with initial JAVA7 Environment
Close Eclipse
Copy Content of Folder XXXXX_OLD to XXXXX
Start Eclipse. No Compilation Error anymore for my Constructor ZipFile(1,2)
I would really like to know the right way. I only gave this solution for probably help other peoples with the same issue. Use this Method on your own RISK! Its messy.

Can't change the jre version in eclipse

I got an error "Syntax error, 'for each' statements are only available if source level is 1.5 or greater" in eclipse.
The jre system library being used is oracle-java-6 and I also enable project specific settings and set complier level to 1.6 but the error is still there.
Please help, thanks ahead.
4. ERROR in /home/johnny/Application/GWTPV/ParaViewWeb/WebServer/PWApp/src/org/paraview/server/AvailableDataFilter.java (at line 65)
ArrayList<FileBean> tmpfileNames = new ArrayList<FileBean>();
^^^^^^^^
Syntax error, parameterized types are only available if source level is 1.5
Look at the tab "Java compiler" in your project properties. If your default jdk compilance is less than 1.5 you should check "Enable project specific settings" and edit "Compiler compilance level" to 1.5, 1.6...
Check out the build path configuration (In the package viewer select the project root element and right mouse clic). Then check the Library setting. Often changing the JRE leaves the Library still set to 1.5.
Right click on the project -> Build Path -> Configure build path
or 1B. Right click on project -> properties -> Java build path
or 1C. Find the error in the Problems view, select it and click [ctrl]+[1] -> Configure build path
Open Libraries tab -> choose add library (or edit an exsting JRE on the list) -> JRE -> Alternate JRE -> click Installed JREs -> choose one
If you can't see the JRE you're looking for on the list (that is version 1.5 or greater):
Add -> standard JVM -> in JRE home field enter the location of your JRE on the disc.

Categories

Resources