Switch + enum ????

Hello all,
This is a simple example in which i use switch statement to compare enum value, ok
package mypackage;
public class Test {
public static void main(String[] args) {
enum Color {red,green,blue}
Color c1 = Color.red;
Color c2 = Color.green;
Color c3 = Color.blue;
switch(c1){
case red:
System.out.println("red");
break;
case green:
System.out.println("green");
break;
case blue:
System.out.println("Blue");
break;
/* It seems simple as u all may agree, but when i execute the coe, an exception is thrown : "java.lang.ClassFormatError: mypackage.Test$1"
when i press the exception it directs me to the switch keyword !!
any one knows why ? please help
*/

Man, why do you keep like addressing everyone like man, man, you know?
I really feel that what you are demonstrating most of all thus far is a great example of why neophytes should not use IDE's. Your description of the error and the way you threw in that bit about ClassFormatError coupled with differing versions smells.
I think when you do post code that compiles you'll still have the basic problem of an incompatible runtime and compiler. I suggest putting away the IDE for now until you have resolved this issue.

Similar Messages

  • Ecard not being generated

    Hi there, basically I followed a tutorial in order to make an Ecard for work.
    So far the user can enter the data on the ecard, then using PHP the data is stored in a directory on my server and the card is emailed to the recipient. All this works fine so far, however when the recipient clicks the link, the page is blank.
    I was wondering if anybody could take a look at my PHP and see if there's anything I'm doing wrong?
    <HTML>
    <HEAD>
    <TITLE>Here's Your Valentine's Card</TITLE>
    <?
    $ENum=$_GET['ENum'];
    $EcardText=$_GET['EcardText'];
    switch ($ENum) {
        case '1':
        $goto = "Ecard1.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '2':
        $goto = "Ecard2.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '3':
        $goto = "Ecard3.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '4':
        $goto = "Ecard4.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '5':
        $goto = "Ecard5.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '6':
        $goto = "Ecard6.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '7':
        $goto = "Ecard7.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
        case '8':
        $goto = "Ecard8.swf?EcardText=".$EcardText;
        $Dimensions = "WIDTH=340 HEIGHT=600";
        break;
    ?>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
    </head>
    <body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">
    <center>
    <script type="text/javascript">
    AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0','<? print "$dimensions";?>','<? print "$Dimensions";?>','src','<? print "$goto";?>','quality','high','bgcolor','#FFFFFF','pluginspage','http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash','mo vie','<? print "$goto";?>' ); //end AC code
    </script><noscript><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
    <? print "$Dimensions";?>>
    <PARAM NAME=movie VALUE="<? print "$goto";?>"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="<? print "$goto";?>" quality=high bgcolor=#FFFFFF  <? print "$Dimensions";?> TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
    </OBJECT></noscript>
    </center>
    </BODY>
    </HTML>

    ohh, if you'd like to try it yourself it's here;
    http://www.richard-walton.com

  • Why "null" value is impossible in "switch(val) {case null: }"  for enums?

    I'm wondering why Java 5.0 does not allow null values
    as options in switch statement:
    If type E is "enum" then the following language construction is
    not allowed:
    E val;
    switch(val) {
       case A:
         break;
       case B:
           break;
       case null:   // this is not allowed
            break;
    }Can somebody explain me why Java does not support it? I beleave that
    some serious reasons were for that.
    As we know enum types can have "null" values and in case I use nulls
    for my enumerations the code with "switch" statement becomes quite urgly because it is necessary to handle 2 separate execution paths:
    null and not null.
    Thanks

    I really don�t know too much about 1.5, but I can tell you that for 1.4 the switch receives as a parameter an int or anything that can be casted automatically to an int. Therefore you can�t never use null cause int, char, short, byte can�t never take as a value null.

  • Enum class not supported for switch() statement in 12.4 beta?

    Hi fellow 12.4 beta testers,
    It would appear "enum class" isn't supported for switch() statements in the 12.4 beta. This compiles fine under clang and g++. Will this be fixed for the final release? This currently causes compile errors for us, since __cplusplus >= 201103L evaluates to true, so our code uses "enum class" instead of plain "enum". It looks like the C++11 standard says it should be supported:
       Switching on enum class in C++ 0x - Stack Overflow
    Many thanks,
    Jonathan.
    $ cat test.cpp
    #include <iostream>
    enum class Ternary { KnownFalse = 0, KnownTrue = 1, Unknown = 2 };
    int main( void )
       Ternary foo;
       switch ( foo ) {
          case Ternary::KnownTrue:
          case Ternary::KnownFalse:
          case Ternary::Unknown:
             std::cout << "Success\n";
    $ clang++ -std=c++11 test.cpp
    $ g++ -std=c++11 test.cpp
    $ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -std=c++11 test.cpp
    "test.cpp", line 8: Error: Cannot use Ternary to initialize integral type.
    "test.cpp", line 8: Error: Switch selection expression must be of an integral type.
    "test.cpp", line 9: Error: An integer constant expression is required for a case label.
    "test.cpp", line 10: Error: An integer constant expression is required for a case label.
    "test.cpp", line 11: Error: An integer constant expression is required for a case label.
    5 Error(s) detected.

    Thanks for reporting this problem! I have filed bug 18499900.
    BTW, according to the C++11 standard, the code is actually not valid. Section 6.4.2, switch statement, says an implicit conversion to an integral type is required, which is not the case for for a scoped enum (one using the "class enum" syntax). This limitation was raised in the C++ Committee as an issue to be fixed, and the C++14 standard makes the code valid.
    As a workaround, or to make the code conform to C++11, you can add casts to int for the enum variable and the enumerators.
    Message was edited by: Steve_Clamage

  • Help with Switch statements using Enums?

    Hello, i need help with writing switch statements involving enums. Researched a lot but still cant find desired answer so going to ask here. Ok i'll cut story short.
    Im writing a calculator program. The main problem is writing code for controlling the engine of calculator which sequences of sum actions.
    I have enum class on itself. Atm i think thats ok. I have another class - the engine which does the work.
    I planned to have a switch statement which takes in parameter of a string n. This string n is received from the user interface when users press a button say; "1 + 2 = " which each time n should be "1", "+", "2" and "=" respectively.
    My algorithm would be as follows checking if its a operator(+) a case carry out adding etc.. each case producing its own task. ( I know i can do it with many simple if..else but that is bad programming technique hence im not going down that route) So here the problem arises - i cant get the switch to successfully complete its task... How about look at my code to understand it better.
    I have posted below all the relevant code i got so far, not including the swing codes because they are not needed here...
    ValidOperators v;
    public Calculator_Engine(ValidOperators v){
              stack = new Stack(20);
              //The creation of the stack...
              this.v = v;          
    public void main_Engine(String n){
           ValidOperators v = ValidOperators.numbers;
                    *vo = vo.valueOf(n);*
         switch(v){
         case Add: add();  break;
         case Sub: sub(); break;
         case Mul: Mul(); break;
         case Div: Div(); break;
         case Eq:sum = stack.sPop(); System.out.println("Sum= " + sum);
         default: double number = Integer.parseInt(n);
                       numberPressed(number);
                       break;
                      //default meaning its number so pass it to a method to do a job
    public enum ValidOperators {
         Add("+"), Sub("-"), Mul("X"), Div("/"),
         Eq("="), Numbers("?"); }
         Notes*
    It gives out error: "No enum const class ValidOperators.+" when i press button +.
    It has nothing to do with listeners as it highlighted the error is coming from the line:switch(v){
    I think i know where the problem is.. the line "vo = vo.valueOf(n);"
    This line gets the string and store the enum as that value instead of Add, Sub etc... So how would i solve the problem?
    But.. I dont know how to fix it. ANy help would be good
    Need more info please ask!
    Thanks in advance.

    demo:
    import java.util.*;
    public class EnumExample {
        enum E {
            STAR("*"), HASH("#");
            private String symbol;
            private static Map<String, E> map = new HashMap<String, E>();
            static {
                put(STAR);
                put(HASH);
            public String getSymbol() {
                return symbol;
            private E(String symbol) {
                this.symbol = symbol;
            private static void put(E e) {
                map.put(e.getSymbol(), e);
            public static E parse(String symbol) {
                return map.get(symbol);
        public static void main(String[] args) {
            System.out.println(E.valueOf("STAR")); //succeeds
            System.out.println(E.parse("*")); //succeeds
            System.out.println(E.parse("STAR")); //fails: null
            System.out.println(E.valueOf("*")); //fails: IllegalArgumentException
    }

  • BUG: JDeveloper 10.1.3.0.3 EA - Exception in switch using enum

    Hi,
    I was encountered runtime exception in switch statement, if I use enum.
    In the next example the exception:
    Exception in thread "main" java.lang.ClassFormatError: Invalid field attribute index 0 in class file com/crcdata/enumtest/client/EnumTest$1
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         at com.crcdata.enumtest.client.EnumTest.main(EnumTest.java:13)
    is thrown on line "switch (season)".
    package com.crcdata.enumtest.client;
    public class EnumTest {
      public enum Season { WINTER, SPRING, SUMMER, FALL }
      public EnumTest() {
      public static void main(String[] args) {
        EnumTest enumTest = new EnumTest();
        Season  season = Season.WINTER;
        switch (season) {
          case WINTER:
            System.out.println("Season: " + season.name());
            break;
          default:
            System.out.println("Another season");
            break;
    }This exception occur only if use ojc compiler. The javac compiler is OK.
    Versions:
    JDeveloper 10.1.3.0.3 EA
    J2EE 1.5.0_05
    Regards,
    Petr

    Thanks for reporting this. I filed bug 4720493 on this.

  • Use Enum to Switch on Strings where one string is a java reserved word.

    Hi,
    I'm having problems switching on a string using enums, when one of the strings is a java reserved word. Any suggestions would be appreciated. Or maybe even a suggestion that I should just be stringing together if-else if and doing string compares rather than a switch.
    I've been using the following method to switch on strings.
    public enum MyEnum
    foo, bar, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    Then I can switch like
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    break;
    Now I have run into the problem where one of the strings I need to use is "int", which is a reserved word in java, so I have to modify.
    What is the best way to handle this?
    I could just not add it to the Enum and handle it at the switch like this...
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    if(someString.equals("int") {  ... }
    break;
    OR...
    I could change the Enum, and return intx, by checking if the string is "int". I could check before the valueOf, or during the exception, but I know it's not good practice to use Exceptions in the normal execution of your code... as it's not really an exception.
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    if(string.equals("int") { return intx; }
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    OR...
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) {
    if(string.equals("int") { return intx; }
    else return novalue;
    }

    My advice is still to not name the enum the same as the value of the string you want to test for. That page I linked to shows how to have enums with parameters. Then you could have an enum whose name is (say) JavaInt and whose string value is "int".
    But frankly if I wanted to map Strings to actions I would just use a Map<String, Action> instead of trying to force my code into an antique construction like switch.

  • Enum and switches

    I have an enum (MessageType) but I am not sure how to read it on the server end.
    Right now I have this statement:
    in = clientSocket.getInputStream();
    switch(in.read())
    case MessageType.LOGIN:  System.out.println("Login"); break;
    }But this does not work. What I am trying to do is construct a message on the client side where the first byte represents the message type so I know how to parse it on the server end. Am I going about this right?
    Edited by: vr_84 on Feb 10, 2009 11:14 AM

    I've changed my enum to a couple of public static final ints:
    final int LOGIN = 0;
    final int LOGOUT = 1;And in my client I have:
    out = socket.getOutputStream();
    out.write(LOGIN);
    out.flush();Then in my server I create a new thread for each client. In the thread I have:
    in = new DataInputStream(clientSocket.getInputStream());
    try
         switch(in.readInt())
              case LOGIN:  System.out.println("Login"); break;
    catch (IOException e) {
         e.printStackTrace();
    }I execute the server first and it runs without errors, then I run the client on the same PC. After doing so I get the following error:
    java.net.SocketException: Connection reset
         at java.net.SocketInputStream.read(Unknown Source)
         at java.net.SocketInputStream.read(Unknown Source)
         at java.io.DataInputStream.readInt(Unknown Source)
         at ClientHandler.run(ClientHandler.java:37)
    Line 37 refers to my switch statement. Thanks for the help so far guys.

  • Switch statement with println() for enum

    Hi,
    I have this exercise maybe you could help with:
    I have to create an enum class and then print out a description of each of the values from a switch.
    This is what I've done..
    enum PaperCurrency {
         FIVE, TEN, TWENTY, FIFTY, ONE_HUNDRED, TWO_HUNDRED
    public class Ex22 {
         PaperCurrency amount;
         Ex22(PaperCurrency amount) {
              this.amount = amount;
         void describe() {
              switch(amount) {
              case FIVE:               System.out.println("five dollar note");
              case TEN:               System.out.println("ten dollar note");
              case TWENTY:          System.out.println("twenty dollar note");
              case FIFTY:               System.out.println("fifty dollar note");
              case ONE_HUNDRED:     System.out.println("a hundred dollar note");
              case TWO_HUNDRED:     System.out.println("two hundred dollar note");
    static void main(String[] args) {
              Ex22
                   fiveDollars = new Ex22(PaperCurrency.FIVE),
                   tenDollars = new Ex22(PaperCurrency.TEN),
                   twentyDollars = new Ex22(PaperCurrency.TWENTY),
                   fiftyDollars = new Ex22 (PaperCurrency.FIFTY),
                   aHundredDollars = new Ex22 (PaperCurrency.ONE_HUNDRED),
                   twoHundredDollars = new Ex22 (PaperCurrency.TWO_HUNDRED);
              fiveDollars.describe();     
    }There are no compilation errors.
    The print out on the console is like this for fiveDollars.describe():
    five dollar note
    ten dollar note
    twenty dollar note
    fifty dollar note
    a hundred dollar note
    two hundred dollar note
    and it is supposed to be:
    five dollar note.
    My question is how to only print out the relevant description instead of all of them? Is my switch wrong?
    Thanks for any help

    If you can, it makes more sense to add functionality to an enum type than to write switch statements:
    public enum PaperCurrency {
        FIVE("five dollar note"),
        TEN("ten dollar note"),
        TWENTY("twenty dollar note"),
        FIFTY("fifty dollar note"),
        ONE_HUNDRED("one hundred dollar note"),
        TWO_HUNDRED("two hundred dollar note");
        private String description;
        private PaperCurrency(String desc) {
            description = desc;
        public String getDescription() {
            return description;
        public static void main(String[] args) {
            System.out.println(PaperCurrency.TEN.getDescription());
    }

  • Test coverage of switch when using an enum

    I'm writing a unit test for the following: -
    switch (status) {
        case ACTIVE:
            return "A";
        case POSTED:
            return "P";
        default:
            throw new IllegalArgumentException("unknown status: " + status);
    }Where status variable is an enum type like: -
    public enum BatchStatus {
        ACTIVE, POSTED
    }I'm of the opinion that having the default branch above makes the code safer and more robust (it means that if the enum grows, problems can be immediately identified).
    So the question is... is it impossible to achieve 100% test coverage, but still retain the default branch above? Since the BatchStatus is an enum (and hence final, and cannot be instantiated), I can't create a third mock value that is neither ACTIVE nor POSTED, so I can't test the default branch.
    ???

    rather than use the switch block - which isn't very OO, and is a maintenance pain - why not have the enum itself return these values?
    public enum BatchStatus {
    ACTIVE("A"),
    POSTED("P");
    private BatchStatus(String status) {
        this.status = status;
    private String status;
    public String getStatus() {
        return this.status;
    }that way, the maintenance programmers have no option but to keep the lot up to date. this over-simplified example probably doesn't address your real problem, but it might point you in a direction you hadn't considered before

  • Sun's demo using enum doesn't seem to work for me

    I'm trying to run a demo from the Sun website, http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html, which includes the enum statement:
    public class SwitchEnumDemo {
        public enum Month { JANUARY, FEBRUARY, MARCH, APRIL,
                            MAY, JUNE, JULY, AUGUST, SEPTEMBER,
                            OCTOBER, NOVEMBER, DECEMBER }
        public static void main(String[] args) {
            Month month = Month.FEBRUARY;
            int year = 2000;
            int numDays = 0;
            switch (month) {
                case JANUARY:
                    // etc etc ...
            System.out.println("Number of Days = " + numDays);
    }However, copying-and-pasting the code into NetBeans, I get an error on the enum declaration stating: '';' expected. Warning: as of release 1.5, 'enum' is a keyword and may not be used as an identifier'. Well... I know that. Isn't that why I'm using it in the first place? Or am I confused?
    I'm using NeBeans 5.0 on Java 1.5.0_06.
    Any advice?
    Question 2: Once I get this thing working, is there any way I can get the month as an input from the user, without needing a long block stating
    if (input = "January") month = Month.JANUARY;
    else if (input = "Feburary") month = Month.FEBURARY;
      //etc etcThat is, can the string representation of a month be somehow kept within the enumerated Month itself, and that be used to check the user's input?
    Thanks for any advice!

    However, copying-and-pasting the code into NetBeans,
    I get an error on the enum declaration stating:
    '';' expected. Warning: as of release 1.5, 'enum'
    is a keyword and may not be used as an
    identifier'. Well... I know that. Isn't
    that why I'm using it in the first place? Or am I
    confused?
    I'm using NeBeans 5.0 on Java 1.5.0_06.I can't say for sure about that; it seems very odd. However, I do know that my IDE will warn me about those sorts of things if I configure my project for pre-1.5 operation. It allows me to say a project is for Java 1.4 even if I'm using a 1.5 JVM and will mention things like that so that forward compatibility can be considered. I don't suppose this could be the case with your situation?
    You might want to search for all instances of "enum" in your code, though, because it's hard to imagine the one instance which appears in the snippet you posted causing problems.
    Question 2: Once I get this thing working, is there
    any way I can get the month as an input from the
    user, without needing a long block stating{snip}
    Well, in this case you can just do
    for (Month m : Month.values())
        if (m.toString().equalsIgnoreCase(input))
            month = m;
            break;
    }or you can build a Map<String,Month> if you're looking for case-sensitive comparison.
    In general, however, you can put pretty much anything into an enum:
    public enum SomeEnum
        A(0),
        B(0),
        C(1),
        D(0),
        E(2);
        private int value;
        SomeEnum(int value)
            this.value = value;
        public int getValue()
            return value;
    // the following is perfectly legal
    SomeEnum e = methodThatReturnsSomeEnum();
    System.out.println(e.getValue());and you could use that to put some form of identifier in the enumeration object. I have a class around here somewhere which uses an enum to enumerate the operators in an expression parser; the Operator enum constructor accepts an int specifying the operator precedence.

  • How to make my applicatio​n programmat​ically switch between English and Russian

    Greetings from Colorado...
    My application needs to be switchable between English and Russian.  Future languages to add are Spanish and Chinese.  The user selects a language
    from a control before starting the program and then the program changes the Captions, Boolean Texts, Graph Labels, and Enum Type Strings to the
    chosen language.  For Russian, this requires a different set of characters.  I have made substantial progress by:
    Control Panels>Region and Language>Keyboards and Languages>Change Keyboards added Russian>Keyboard>Russian on my development
    computer.
    In the LabVIEW.ini file, I added UseUnicode=TRUE (thanks to a suggestion found in this forum)
    Made property nodes for controls and used properties such as Interpret As Unicode (True for Russian, False for English), Text, Font Name, Font Size, etc.
    I have used fonts Arial and Arial CYR for Russian and MS Sans Serif for English
    Set the keyboard for Russian and enter Cyrillic characters into text constants that are set for Arial or Arial CYR font.  Sometimes one works and
    sometimes the other works.  As long as I set the font name in the property node the same way the text went into the text constant, it generally
    works.  I wish I could understand why one works sometimes and the other works other times!
    I have had trouble with the Boolean Text going off-center when changing fonts and languages and it seems that by setting the Lock Text In Center
    property to False and then True again, it seems to work.  Often changing Boolean texts between short and long texts causes some of the long text
    to be non-displayed; I have remedied this by explicitly setting the width of the Boolean text in a property node.
    Often, the Russian text appears as gibberish with strange right-angle characters, :s, =s, and tiny numbers.  I have been able to remedy this on my
    development computer by ensuring that the text constant on the block diagram has the same size as the caption is supposed to have.  This
    is not necessary for normal programming in English, but it seems to help here.  But it doesn't always solve the problem.
    Sometimes the English text appears as Chinese gibberish in an Enum Type selection list or in a graph label.  On my development computer,
    it seems that making the text the last property to change helps here.
    By changing the sequences of assignments to a single property node with a long list of properties, I have been able to make some of these
    controls to switch between languages without gibberish showing up.
    A few hours ago, I had the Russian strings in the Enum Type control working, except that when selecting from the available items, only the first
    word of the Russian string was displayed.  Two of the items start with the same word, so the user can't distinguish them.  
    At that time the English strings were appearing as Chinese gibberish while the list during the selection process displayed in English.  As soon
    as I changed the selection, future attempts to change the selection gave Chinese gibberish during the selection process, too.  But this was only
    a problem in the executable version; the source-code version worked fine.
    In an attempt to get rid of the Chinese gibberish, I made new constants and retyped the items into them.  This worked!  But then, the Russian
    stopped working and gave gibberish angles and tiny numbers, even though I didn't touch any of the code that sets the properties in Russian mode.
    After trying a few sequences of setting the properties for the graph X label on page 2 of my tab control, this label started working correctly for both
    languages.  But the text of that label comes through on page 1 of the tab control, partly obscured by other controls on that page.  After the
    program runs a few more seconds, these shadows disappear.
    Most times I restart LabVIEW, I get an error message saying there was a crash due to fontmgr.cpp, line 7494.  But there actually wasn't a crash.
    My computer has Windows 7 64-bit.  Deployment Computer has Windows 7 32-bit.  LabVIEW version is 8.5.  
    I have probably 50 or 100 more controls and indicators to change to language programmability and figuring out all this stuff for each one is
    terribly time-consuming and there is no assurance that all of them will ever work.  
    At this point, I'm hoping that I am on an entirely wrong path and someone will send me a clue to get me on a path that is more predictable.
    Thanks in advance to all who post ideas!
    Cheers
    Halden 

    Hi All,
    I've made a lot of progress on this translation, but it's been really hard.  There are lots of weird things going on that must be logical because they're in a computer, but I can't figure out what the logic is.  When changing a font on a caption using the front panel, it sometimes changes the font on the caption and sometimes doesn't although the indicator always indicates the new font.  Removing the first character of the unicode font string being sent to the caption seems to help...huh?  Anyway, tabs still can't change language programmatically, and niether can ring controls (some kinds will take the new list of strings, but when selecting, they only display the first word of the string!).  Boolean text can be reprogrammed, but only if the boolean text is set to be the same for both true and false states.  When reprogramming captions on a non-displayed page of a multi-page tab-controlled user interface, the new text appears on the current page until I change pages back and forth.  What a pain!
    Sooo, NI....does LabVIEW 2011 have support for unicode fonts?  Or, is there anything else in the new control style that will support programmatic language changing?
    Halden 

  • What's the deal with enums?

    Hello,
    I'm trying to familiarise myself with the new Java features that project Tiger (Java 1.5) will introduce. I come from a C++ programming background. I very briefly studied enums whilst I learned C++ and never used them in my programs, so I was, quite frankly, relieved when I learned that Java didn't support them.
    But now it does.
    I'm wondering, from a software design and engineering perspective, what benefit enums will add to the Java language and software engineering in general. I have read some pleas and arguments for enums. As I understand those arguments, proponents feel that minor ledgibility improvements to switch statements (which some OO programmers don't use on the basis that it weakens the object-orientedness through its goto-esque break statements) necessitate the addition of a whole other structure.
    Out of curiosity, wouldn't it be more advantageous for Sun to put their efforts into supporting constant strings in switches in addition to primitive data types if people are so concerned with clarity?
    I fail to understand what enums will do that constant string arrays or constant values cannot. I would like to think that Sun wouldn't add C++ features unless if there was a reason to do so, so I believe that there are good reasons to introduce this feature.
    Please help clarify this confusion.
    Thank you!

    Comments on the previous posting inline. Note: I'll go off on a few tangents, but try to always return to the issue of enums. The fact that I go off on tangents (related initially to an enum type example) should show that enums help eliminate numerous problems.
    Fair enough, but wouldn't this accomplish the same thing in
    a slightly wordier wayPretty much. But you still have the validation code in there yourself:
    currentDirection = ( direction > 0 && direction < 5 ? direction : 0 );People can still accidentally enter an invalid value, and it won't get caught by the compiler. So, I could call set(Compass.WEST) and hope/expect that is equivalent to set(Direction.LEFT). This will only occur if both Compass.WEST and Direction.LEFT are the same int value. If they are not, then we are in trouble. Worse, still if Compass.WEST and Direction.RIGHT are the same value, the code will compile, and run without any illegal value flagging, but our traveller will go off in the wrong direction.
    Error handling tangent: Given the implementation, the error handling is not performed in set, rather the illegal value is captured as a zero, which must be dealt with at a later time - say in a switch statement that calls get. This is not a good idea - it increases the "distance" between the error occuring (bad call to set) and the error being detected (if xInt != 0). The larger the distance, the harder debugging is. If you throw an exception in set the bug is immediately flagged. With enums, none of this should be necessary.
    Implementation tangent: set, get and currentDirection are static. This is not a good idea - it only allows one direction. If you have multiple travellers, each would have a Direction object, but (sticking with constants) UP, etc. would still be static.
    I keep the switch statement in my enum workaround, but I believe that
    the second reply suggested that enum could altogether eliminate the
    use for switch statements. How exactly would it do that?enum in its simplest form would not remove switch. However, using an extension of the type-safe enum idiom (i.e. the current Java approach to enums), you can embed direction specific logic in each of the "enum" members. If I understand the enum-spec correcly, this will also be possible with the Java 1.5 enum language facility.
    So, for an example, sticking with the domain: Consider a class Location, with x and y elements, and a Direction. The non-OO, non-enum approach would be as follows:
    class Location {
        int x,y;
        void move (final int direction) {
            switch (direction) {
                case UP:
                    --y;
                    break;
                case DOWN:
                    ++y;
                    break;
                case LEFT;
                    --x;
                    break;
                case RIGHT:
                    ++x;
                    break;
                default;
                    throw new RuntimeException("Invalid direction " + direction);
    class Direction {
        public static final int UP = 1;
        public static final int DOWN = 2;
        public static final int LEFT = 3;
        public static final int RIGHT = 4;
    }Note that I've deliberately been loose with my visibility. All logic is in Location, and Direction is dumb. If we go with a type safe-enum idiom, we get:
    class Location {
        int x,y;
        void move (final Direction direction) {
            if (direction == Direction.UP) {
                --y;
            } else if (direction == Direction.DOWN) {
                ++y;
            } else if (direction == Direction.LEFT) {
                --x;
            } else if (direction == Direction.RIGHT) {
                ++x;
            } else { // direction is null
                throw new NullPointerException("null direction");
    class Direction {
        public static final Direction UP = new Direction();
        public static final Direction DOWN = new Direction();
        public static final Direction LEFT = new Direction();
        public static final Direction RIGHT = new Direction();
        private Direction () {} // the ctor is private to limit instances
    }This code is a rewrite of the int approach, but is "type-safe". We've moved from switch to if as we can't switch on object references. Note: there is still error handling code, as you're not "null-safe" (I don't know what the Java 1.5 spec says about this)
    Little else has changed - the responsibilities are still the same. We can address this by going OO, which removes the if (formerly a switch) statement, but does couple the classes.
    class Location {
        int x,y;
        void move (final Direction direction) {
            direction.move(this);
    class Direction {
        private final int xOffset, yOffset;
        private Direction (final int xOffset, final int yOffset) {
            this.xOffset = xOffset;
            this.yOffset = yOffset;
        public static final Direction UP = new Direction(0,1);
        public static final Direction DOWN = new Direction(0,-1);
        public static final Direction LEFT = new Direction(-1,0);
        public static final Direction RIGHT = new Direction(1,0);
        void move(final Location location) {
            location.x += xOffset;
            location.y += yOffset;
    }This removes any conditional logic, embedding (constructor parameterised) logic within Direction. It also eliminates the "null-safe" check, as direction.move(this) will throw an NPE if a null is passed.
    Also, I've read some things saying that enum reduces 'boilerplate'
    code. What exactly does that and 'boilerplate' mean?The Direction class is an example of the type-safe enum approach currently used in Java. It has been enhanced with logic for movement. Even if I dropped this logic, there is still functionality worth adding to the Direction class - a toString method that returns one of "UP", "DOWN", etc (shown next); a way to serialize the object and retain reference equality - you have to write a readResolve method (not shown).
    class Direction {
        private final String name;
        private Direction (final String name) {
            this.name = name;
        public static final Direction UP = new Direction("UP");
        public static final Direction DOWN = new Direction("DOWN");
        public static final Direction LEFT = new Direction("LEFT");
        public static final Direction RIGHT = new Direction("RIGHT");
        public String toString() {
            return name;
    }Once you've written this code for one type-safe enum, you've written them for them all. You copy-cut-paste, and rename the class/elements. All this code is predictable. It is "boiler plate". Now, if you gave me a compiler that generated all this code for me, when I present it with
    enum Direction {UP, DOWN, LEFT, RIGHT}; then I've got something that reduces my boiler plate code to zip.... Enter the Java 1.5 compiler.

  • Switch statement with enumerated types

    Hello,
    I'm currently having problems (error in eclipse) using enums in a
    switch block. Eclipse says:
    "The enum constant Constants.AnalysisType.<each case> reference cannot be qualified in a case label.
    for each of the cases that I try to use the enumerated type. My code
    looks something like this:
    switch (analysisType) {
    case Constants.AnalysisType.NONE:
        break;
    case Constants.AnalysisType.MVGAVG:
        break;
    }(With a number of cases omitted).
    where analysisType is the enumerated type defined in
    a file called Constants.java.
    The class where the error is occuring is located at:
    package myprog.ui.ViewPanelTab; and the enumerated type is declared at:
    package myprog.utility.Constants;I have the required import statements in the ViewPanelTab class.
    I have tried
    public, private, public static, private static as modifiers on the enumeration.
    Any ideas as to why eclipse won't let me do this.
    Thanks for any help
    Devon

    Why is it that the entire switch and all of its cases have the same locality ?By "locality" do you mean "scope" (i.e. the inability to declare two variables with the same name)? I find it rather irritating that I can't write switch (foo)
        case bar:
            int quux = ...
            break;
        case baz:
            int quux = ...
            break;
    }My guess as to the reason for the decision to disallow this is that otherwise removing a break statement could create a compiler error where there previously was none, and that this would be confusing. It is possible to create a fresh scope, though, by using braces:switch (foo)
        case bar:
            int quux = ...
            break;
        case baz:
            int quux = ...
            break;
    }

  • Using enum's from one class in another?

    heya,
    I have two classes, Predator and Simulation, and Predator has an public enum 'target' inside it.
    Simulation needs to use a switch statement based on target (Simulation contains a list of Predators, and I'm returning type target to Simulation), but I am getting errors when compiling the two classes from the commandline (for some weird reason, it works fine in Eclipse - both classes are in a package 'lepidoptera', which I originally thoguht was the issue).
    Errors are like (5 of these):
    Simulation.java:64: an enum switch case label must be the unqualified name of an enumeration constant
                    case (mimic):Any ideas?
    Thanks,
    Victor

    This works for moi:
    public class Predator {
        public enum Target {SEITAN, TOFU, TEMPEH}
    public class Simulation {
        public static String f(Predator.Target target) {
            switch(target) {
                case SEITAN:
                    return "yuck";
                case TOFU:
                    return "ugh";
                case TEMPEH:
                    return "crikey";
                default:
                    return "nuts";
        public static void main(String[] args) {
            System.out.println(f(Predator.Target.SEITAN));
            System.out.println(f(Predator.Target.TOFU));
            System.out.println(f(Predator.Target.TEMPEH));
    }And do you know that an enum can be a top level class? In other
    words, that you can create the one-line file Target.java:
    public enum Target {SEITAN, TOFU, TEMPEH}

Maybe you are looking for

  • Best Way to Export Single Tracks in Audition

    Hello, What is the best way to export one single track (stereo or 5.1) from a multiple track mix in the Multitrack Editor if I want to make it mono? Is it by just muting the tracks I don´t want in the final mixdown and then selecting a mono Master in

  • Correct way to compress 16X9 file for the web

    Hello: Shot an HDV project. After importing converted files to DVCProHD. 1280X1080 16X9. Edited 5 min. piece. Exported QT with current settings. Need to upload to You Tube. Please tell me...what's the best choice in Compressor? I tried H.264 Streamin

  • How do I transfer photos from iPhoto9 to another location on the same machine

    If I want to transfer photos from my iPhone, I am told that I have to use iPhoto. I have iPhoto 9, and I transfered the pix to iPhoto OK, but now I want to move them to Adobe Bridge and this where I seem to be having difficulty. Any help greatly appr

  • Windows 8.1 Errow in all 3 of my computers

    Firefox is not working correctly in windows 8.1 computers. It does not shut down completely and then does not open with this error message. Attaching.... [email protected].. The window displays the message firefox is already running but is not respon

  • System Refresh ECC6 Windows/MSSQL

    Hi everybody, I have to make a refresh from the PRD system to the QAS system. I do not need to make a system copy. I can not find any documentation or thread to do it. I red some documentation about detach/attach the database or backup/restore it. I