Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Collection specific elements not generic problem

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

I am facing an error which is giving me a problem. I google it but it couldn't help.
I am running the Eclipse Europa on Windows vista with jdk & jre 1.6.
All the things works fine except:

Problem::

Following is my code:



I wanted to add only String values in the List not other type of values.
But,

It gives me compilation error at LINE 1 at the point of .

ERROR::
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "<", invalid AssignmentOperator
Syntax error on token "=", != expected
Syntax error on token "<", ( expected
Syntax error on token "(", invalid Expression

at Ba.main(Ba.java:22)


When i use plain code like


When i use above line code it works fine.


What shall i have to do get rid of it. Because of this my whole developed project which i already done on Windows XP platform getting messed up.

Thanks in advance.
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,
It looks like you are compiling with an earlier version of Java. Can you confirm your project is using Java 1.4 in Eclipse?

This sounds like a tooling problem so I'll move it to our IDEs forum.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
It looks like you are compiling with an earlier version of Java. Can you confirm your project is using Java 1.4 in Eclipse?



I once again checked the version of the java by firing command
java -version in command prompt
and it shows java 1.6.0_04 version

Thanks again
 
Marshal
Posts: 74634
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have on command prompt and what you are using in Eclipse can be two very different things. Get the properties for the project you are working in on Eclipse, that might be using Java 1.4 compatibility.
 
Jeanne Boyarsky
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might need to check in two places. The preferences for the Java project itself. And if it says "use defaults", you need to check the workspace preferences too.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends sorry in advance to ask you a simple question again

How can i see which JDK version i am using in Eclipse?

As you suggested i saw the settings in the Preference menu OR in Project properties
And i found jre 1.6 only in the Library tab of the Java Build Path.

Thank you.
 
Jeanne Boyarsky
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Shilpakar:
How can i see which JDK version i am using in Eclipse?


In the project preferences, go to the "java compiler" option. If "enable project specific settings" is checked, the version # is specified here. If the checkbox is not selected, the version # is in the workspace preferences under java --> compiler. These settings move around a bit in different versions of Eclipse - these locations are for Eclipse 3.3. They were nearby on prior versions, so you should see them in a similar location.

Note that the jar under the build path might not be the version of Java you are using. It's possible to compile against older versions of Java on a newer JVM.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, You are right Jeanne Boyarsky.

Its compiling with older version (i.e. 1.4) of the JDK.

Now, what am i suppose to do so that my Java code will get compile with latest version (i.e. 1.6) of JDK which i already installed on my mahcine ?

Thank you.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for one incorrect information:

Earlier i mentioned that i am using Eclipse europa.
BUT, i am sorry.

I am using Eclipse 3.0 version.
 
Jeanne Boyarsky
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,
I don't believe Eclipse 3.0 supports Java 5. You'll need to upgrade to a later version of Eclipse to use the Java 5 features.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Shilpakar:

Now, what am i suppose to do so that my Java code will get compile with latest version (i.e. 1.6) of JDK which i already installed on my mahcine ?



Eclipse likely *is* already using your JDK. It is *never* using the compiler that is coming with the JDK, but uses its own one. So, to configure Eclipse to compile 1.6 code, you need to *both* point it to the right JDK *and* tell the *eclipse compiler* to act 1.6 compliant.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

originally posted by : Ilja Preuss
you need to *both* point it to the right JDK *and* tell the *eclipse compiler* to act 1.6 compliant.



how can i do that? I mean what are the steps to do that?

Thanks
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Shilpakar:


how can i do that? I mean what are the steps to do that?

Thanks



The steps that Jeanne already provided.
 
Saloon Keeper
Posts: 24824
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's also one more step, and it's very important. You have to actually install the desired JVM into Eclipse. On the Window/Preferences dialog, select Java/Installed JRE's, click the "Add" button and select the directory of the JVM you want to add. You can then select it as the default JVM for the workspace or as a selected JVM for a project.

As to whether or not Eclipse actually uses that compiler for workspace compiling, there seems to be some confusion. Allegedly Eclipse has its own compiler that's gimmicked up to integrate more closely with the IDE and the JRE is actually literally that - a JRE, not a JDK: used by the debugging phase.

As far as I can remember, Eclipse 3.0 supported Java 5, but not Java 6.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Orginally posted by Tim Holloway
As far as I can remember, Eclipse 3.0 supported Java 5, but not Java 6.



Yes, I tried all the things as said above.
And it does not support with JDK 6.Better i will change Eclipse.

Thanks all.
reply
    Bookmark Topic Watch Topic
  • New Topic