2
switch(title)
   {
    case "Return":
          returnBooks();
          break;
  }

strings in switch are not supported in -source 1.6, use -source 7 or higher to enable strings in switch

So, I have already installed JDK7, Why compiler show this message and giving an error while on compiling?

I am using NetBeans

5
  • 2
    Are you compiling directly form the terminal or are you using an IDE ? Commented Sep 27, 2011 at 4:53
  • 1
    Do you have more than one JRE installed on your system? If so, have you specified JDK7 as your JRE of choice? I suspect from the error message you're getting that your system is using JRE/JDK6 even if JDK7 is installed. Commented Sep 27, 2011 at 4:54
  • 1
    Listen to Matt below - you have to use the -source 7 flag. Commented Sep 27, 2011 at 4:56
  • you probably need to configure on the project properties or build configuration panel to set that extra parameter everyone is talking about Commented Sep 27, 2011 at 5:09
  • I appreciate all comments answer but I don't need probably as all users are doing, I required the exact answer which hit the point not surrounding that is why I consult the forum. No one telling in this ways that you are using Ntbeans and go to the Properties>Libraries etc.... Commented Sep 27, 2011 at 6:17

5 Answers 5

16

I hate to say it, but: read the darn error message. It tells you exactly what the problem is.

You are compiling in Java 6 mode, not compiling in Java 7 mode. If you're using javac that comes with JDK 7, as the error message says, use the -source 7 flag:

> javac -source 7 {stuff here}
Sign up to request clarification or add additional context in comments.

4 Comments

Common sense, people, common sense... I'm going to bed.
I think you dont have to be all guru about it... the guy says he has only jdk7 installed ..then why the hell he should give that stupid flag!
Telling people to use their common sense is "guru"? Crikey Bruce, I never knew that that advice was so profound!
@ChingPing the guy says that he already installed JDK7, he not says he has only jdk7 installed.
10

Two key points from the user query:

  1. Already installed JDK7;and
  2. Using Netbeans

So, netbeans came with two package:

  1. With JDK

Means when install the Netbeans 7 it automatically install JDK 7 and set JDK 7 as Default Library.

  1. Without JDK

On the installation of NetBeans 7, it found JDK in the system, and if found it automatically configure the path of library as well, but show you information about the path and version of JDK7.

All of users try to give the correct answer of this query, but no one is in position to answer in the correct way as the user required because user using the Netbeans as well.

With continue the edit version of Hemal Pandya, one thing more is required to configure, which is that

RightClick on  Project > properties > and in the categories option select > source. see the  
**Hemal Pandya** edit version to look at image, the source option is available above the   
Libraries option.

And

then select **Source/Binary Format** form bottom and set it to JDK 7 (= 1.7). this is the exact solution
of user's post and I am 100% sure now String in swich will work

1 Comment

Thanks Both_FM , you are really Genius! Now my problem has resolved
4

In NetBeans, go to the properties of the project and change the java platform to java 7 in libraries

2 Comments

Java platform is already set to Java 7 (Default)in libraries!
bits.netbeans.org/media/register-jdk7.swf Check this link I have already done this activity but still compiler error!
2

I have found a solution: If you are using Netbeans 7.1 (even, 7.0), just you have to follow this: Right Click on Project -> Properties -> Sources -> (On the bottom) Source/Binary Format

Just select JDK 7, and that's all, you can then use strings in switch!

Comments

1

I do not use NetBeans but there seems to be a compliance switch that has defaulted to 1.6. You will have to find that switch and set it to 7, as others have pointed out.

EDIT: I found I found netbeans.org/kb/docs/java/project-setup.html#projects-jdk. You seem to have done the second step of registering jdk. But maybe it is not the default? Follow the instructions to To switch the target JDK of a standard project. Looking at images it seems to be in this dialog:

enter image description here

3 Comments

bits.netbeans.org/media/register-jdk7.swf Check this link I have already done this activity but still compiler error!
Did you also make it default? Or there must be a per project setting
I found netbeans.org/kb/docs/java/project-setup.html#projects-jdk. You seem to have done the second step of registering jdk. But maybe it is not the default? Follow the instructions to To switch the target JDK of a standard project:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.