Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enhanced for loop  RSS feed

 
Namit Puri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using enhanced for loop in my java program and have j2sdk 1.5.0 installed, but still the compiler gives error at the loop statement. Syantax is also correct. Do I need to update the version??

Thanks!!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

If Java 1.5 is properly installed, then it should be working fine. Why don't you post your code and have some more eyes check the syntax?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37222
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Smart Aquarian",
We're pleased to have you here with us at JavaRanch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
artender
 
Namit Puri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

//compiler giving error at the enhanced for loop


EDIT by mw: Added Code Tags to original poster's indentation.
[ August 20, 2006: Message edited by: marc weber ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, your code compiles fine for me, so let's move on to your installation of Java 1.5. What do you get when you type "javac -version" at the command line? (Without a file name, you'll get a long error message, but it should start with the version.)

...javac -version
javac 1.5.0_06
javac: no source files...

My guess is that you're on a Windows machine, and you didn't adjust your PATH variable properly. See Step 5 of these installation instructions for Windows. BUT note that the system checks the PATH variable from left to right, looking for a path that will work. So if you have a path for a prior version of Java listed first, then it will use the prior version.
 
Namit Puri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am working on Windows XP and running the javac -version command returns:
javac 1.5.0-beta
javac: no source files

The step 2 of installation notes recommends to uninstall any beta versions.
What do you reckon?

The path is also set as C:\j2sdk1.5.0\bin;

Thanks!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, clear out any beta versions. (I don't know whether that alone will work, or whether you will need to reinstall the regular version after that.)

Which update of 1.5 are you installing? I think the current version for Windows is Update 8 -- that is, 1.5.0_08.
[ August 20, 2006: Message edited by: marc weber ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not all of the betas included the enhanced for loop.
Not quite sure at which stage it was included.

Indeed you should install the latest production release (_08 by now) and get rid of that beta.
 
Namit Puri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, got it working. Just updated with the latest version.

Thanks to everyone!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!