Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Ran into a JDK error
Ran into a JDK error [message #943642] Sun, 14 October 2012 13:54 Go to next message
Skyler Wittman is currently offline Skyler Wittman
Messages: 1
Registered: October 2012
Junior Member
I am using Eclipse Juno Service release 1 for Linux and ran into a problem.

I'm quite new to programming so please bear with me.

I was using the Java perspective and writing a java program and upon compilation ran into this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted

at PhoneticTranslate.main(PhoneticTranslate.java:22)

So I clicked on the red x at that line where the problem was and it suggested switching to JDK 1.7 and I just hit enter. Now all of my programs have red x's all over them and I'm trying to get back to where I was before, I believe I had JDK 1.6.something.

Thank you.

EDIT: Corrected from Java EE to regular Java perspective, if that makes a difference.

[Updated on: Sun, 14 October 2012 13:56]

Report message to a moderator

Re: Ran into a JDK error [message #944181 is a reply to message #943642] Sun, 14 October 2012 19:00 Go to previous message
Russell Bateman is currently offline Russell Bateman
Messages: 3052
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 10/14/2012 11:54 AM, Skyler Wittman wrote:
> I am using Eclipse Juno Service release 1 for Linux and ran into a problem.
>
> I'm quite new to programming so please bear with me.
>
> I was using the Java EE perspective and writing a java program and upon
> compilation ran into this error:
> Exception in thread "main" java.lang.Error: Unresolved compilation
> problem: Cannot switch on a value of type String for source level below
> 1.7. Only convertible int values or enum variables are permitted
>
> at PhoneticTranslate.main(PhoneticTranslate.java:22)
>
> So I clicked on the red x at that line where the problem was and it
> suggested switching to JDK 1.7 and I just hit enter. Now all of my
> programs have red x's all over them and I'm trying to get back to where
> I was before, I believe I had JDK 1.6.something.
>
> Thank you.

That you'd done originally was something like:

switch( string )
{
case "some string" :
...
case "another string" :
...
case "yet another string" :
...
}

This isn't tolerated before Java 7 (prior to that, the discriminant,
argument to switch, had to be a scalar like int, Integer, enum, etc.

Not sure what happened to you subsequently. It may be that by hitting
Enter, you accepted some quick fix and the quick fix was to switch to
Java 7, but if you don't have Java 7, I don't know why it would have
offered that. Not something I've seen before.

I suggest you a) remove the switch construct and b) revisit your
compiler settings by going to Window -> Preferences -> Java -> Installed
JREs and ensuring there's a proper JDK selected. If there is and it's
jdk1.7..., then you can keep your switch, otherwise ensure that it's
1.6... and you change your code to something like:

if( string.equal( "some string" ) )
...
else if( string.equal( "another string" ) )
...
else if( string.equal( "yet another string" ) )
...

Another place to check would be Window -> Preferences -> Java ->
Compiler and ensure that your compliance level is (1.6 or 1.7) and that
it matches what you have as an installed JDK. Normally, it shouldn't be
possible to go to 1.7 if you don't in fact have jdk1.7... installed.

Ask again with more exact information if you don't stumble upon the
solution after looking into what I suggest here.
Previous Topic:What to add on to Eclipse?
Next Topic:Kill External Program Launched by Eclipse
Goto Forum:
  


Current Time: Thu Apr 17 00:09:27 EDT 2014

Powered by FUDForum. Page generated in 0.06446 seconds