• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch using strings

 
Tim Keune
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a switch structure with a string key. I get the following diagnostic:

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

I'm using NetBeans 7.3.1 with the SDK 1.7.

I'm a relative newbie for java so I don't know how to respond to the error message. I've searched far and wide and either found nothing or a gazillion irrelevant hits.
I'm so frustrated I'm ready to go sideways but that leaves the hole in my knowledge. I'd like to find out how to make this work. The prototype I'm working with is below. It handles responses to a menu selection (which will have dozens of choices.)


I'm hoping this forum is the resource I've been missing....
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of Java do you want to use?

If 1.7, compile accordingly.

If 1.6, you have to rewrite the String-based switch into, say, a series of "equals" statements.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you've got the IDE configured to use Java 1.6.

I've copied this over to the IDEs forum for the Netbeans-savvy to help you out with proper configuration.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the project properties and in the Libraries section make sure that your 1.7 JDK is selected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic