Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse or Java 6 Problem: Syntax Error: For each statements are only available if source level is 5
Eclipse or Java 6 Problem: Syntax Error: For each statements are only available if source level is 5 [message #199061] Mon, 12 March 2007 15:52 Go to next message
Eclipse UserFriend
Originally posted by: siegfried.heintze.com

I am getting the error message (see subject) for the following code on line
14. If I comment out line 14, the program runs properly. Obviously, this is
java 6. Should I not have the for each statement from Java 5 in Java 6?

As I understand it, the scripting stuff is unique to java 6.

Thanks,
Siegfried

1 package helloWorld;
2
3 import java.util.Iterator;
4 import java.util.List;
5
6 import javax.script.*;
7 public class EvalScript {
8 static java.io.PrintStream out = System.out;
9 public static void main(String[] args) throws Exception {
10 // create a script engine manager
11 ScriptEngineManager manager = new ScriptEngineManager();
12 // create a JavaScript engine
13 List factories = manager.getEngineFactories();
14 for(ScriptEngineFactory factory : factories){ }
15
16 ScriptEngine engine = manager.getEngineByName("JavaScript");
17 // evaluate JavaScript code from String
18 engine.eval("print('Hello, World')");
19 }
20 }
21
Re: Eclipse or Java 6 Problem: Syntax Error: For each statements are only available if source level [message #199078 is a reply to message #199061] Mon, 12 March 2007 16:19 Go to previous message
Paul A. Rubin is currently offline Paul A. RubinFriend
Messages: 188
Registered: July 2009
Senior Member
Siegfried Heintze wrote:
> I am getting the error message (see subject) for the following code on line
> 14. If I comment out line 14, the program runs properly. Obviously, this is
> java 6. Should I not have the for each statement from Java 5 in Java 6?
>
> As I understand it, the scripting stuff is unique to java 6.
>
> Thanks,
> Siegfried
>
> 1 package helloWorld;
> 2
> 3 import java.util.Iterator;
> 4 import java.util.List;
> 5
> 6 import javax.script.*;
> 7 public class EvalScript {
> 8 static java.io.PrintStream out = System.out;
> 9 public static void main(String[] args) throws Exception {
> 10 // create a script engine manager
> 11 ScriptEngineManager manager = new ScriptEngineManager();
> 12 // create a JavaScript engine
> 13 List factories = manager.getEngineFactories();
> 14 for(ScriptEngineFactory factory : factories){ }
> 15
> 16 ScriptEngine engine = manager.getEngineByName("JavaScript");
> 17 // evaluate JavaScript code from String
> 18 engine.eval("print('Hello, World')");
> 19 }
> 20 }
> 21
>
>

Sounds as though the compiler is asserting Java 1.4.x compliance. Right
click the project in the Project Explorer, select Properties, then Java
Compiler, and see what Java Compliance is set to. If it's 1.4, you can
check "Enable project specific settings" and set the compliance level to
5.0 or 6.0. You can make that the default for new projects under
Windows -> Preferences -> Java -> Compiler.

/Paul
Previous Topic:provide values in "org.eclipse.ui.prefs"
Next Topic:Pass a paramter IN atl command lines
Goto Forum:
  


Current Time: Sat Apr 20 00:20:14 GMT 2024

Powered by FUDForum. Page generated in 0.08903 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top