0

So after reading another question post I realized my question had changed. It is essentially, why can't I change my compliance level in Eclipse from 1.6 to 1.7 but I'm going to leave the body of my question as it was typed originally.

This is a very specific question but I'm going through a series of Java courses online and one of the lessons deals with switch. The example code uses switch with strings (both the course and I use Eclipse). When I try to run the code it gives me an error stating "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted"

I understand this is because strings can only be used with switch in Java 7. Thus I went about installing Java 7 in terminal using some instructions I found online. Afterwards Eclipse wouldn't run at all. I went to switch back to Java 6 and found I was running Java 7 Oracle but had option to change to Java 7 OpenJDK so I did. Eclipse is working again but I still get the same error as before. Why is this? And is there a way to fix it?

For some added info, here's what terminal returns when I type in "sudo update-alternatives --config java" to switch between versions.

glitch@glitch-Inspiron-1720:~$ sudo update-alternatives --config java
[sudo] password for glitch: 
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-oracle/jre/bin/java         1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode
  3            /usr/lib/jvm/java-7-oracle/jre/bin/java         1062      manual mode

Press enter to keep the current choice[*], or type selection number:"

As you can see I'm currently using java-7-openjdk where as before I was using java-7-oracle (which resulted in Eclipse plain out not working) and before that I assume I was using java-6-openjdk (this is what I run Minecraft in after all but who knows).

More specifically I'm using:

glitch@glitch-Inspiron-1720:~$ java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1~0.12.04.2)
OpenJDK Server VM (build 24.51-b03, mixed mode)

I looked at this question: Can't use Java 7 from Eclipse?

I tried following the instructions given therein all the way up to changing Properties > Java Compiler > Compliance Level to 1.7

I found the location of my JVM was /usr/lib/jvm/ but when I put this in for JRE home in Eclipse it gives me this error: "Target is not a JDK Root. Java executable was not found"

I am quite frustrated. Can anyone help? Also, please forgive my ignorance, I am very new at all this.

1

Fixed! I uninstalled and reinstalled Java and changed the location of my JVM to /usr/lib/jvm/java-1.7.0-openjdk-i386. The solution was much simpler than I thought. Now I feel very silly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.