Problem with switch

Hi,
I have a problem using switch statement.
I have a class named Resources in which I declare all the final variables.
I have created an instance of Resources named res in the main class.
But I cannot use the final variables in the main class in the following way:
switch (a) {            //a is int
   case res.LEFT:       //LEFT is a final int variable in Resources     //PROBLEM
      //do something
   break;
}The compiler complained: Constant expression required
What is the matter?
Thank you.
Nelson

Here is how the Resources class looks like:
public class Resources {
  public final int LEFT = 0, RIGHT = 1;
}In my main class, I just used the following to create the object:
private Resources res = new Resources();

Similar Messages

  • Problem with switching tabs in top level navigation for Roles

    Hi,
    I've created two tabs (based on two roles) in the portal top level navigation menu. When clicking the first one it opens as it should. Then when clicking on the second tab it will not open, instead the first tab open up again, it sort of switches back automatically.These  two roles  are  basically consists of worksets and iviews(accessing to r/3).
    Does anyone have any expericene with this type of problem?
    please  suggest me
    Thanks
    Aravinda

    Hi Aravinda
    Please check this link
    Re: Problem with switching tabs in top level navigation
    Regards
    Geogi

  • Cp1700 - Any problems with switching existing printer with stored printer?

    I am having problems reading the LCD panel for my cp1700 (not all the text shows - common problem). I have another cp1700 that I have had stored for about 5 years (saving for parts. I think this "stored" printer squeaked when printing). I considered switching the LCD panels but it looks as if this is a complicated procedure. So I am wondering if I will encounter any problems with switching the printers? I will be putting in new ink cartridges but wondering if the printheads will cause a problem after being stored for so long?

    This don't completely resolve your concerns, but I've had no trouble printing from OS X 10.7 to an Epson Artisan 810 connected to a Mac running OS X 10.6.8.  I may even have been able to print to it wirelessly, but I can't remember.  Apple issued an update to the Epson printer drivers fairly recently, which one would hope would have addressed any issues.  In any case, I'd make a bootable clone of your Mac before you upgrade.  If things aren't as you hope, then you can restore the clone to your main disk drive and be back with OS X 10.6.

  • Having problem with switching it on

    please am having problem with my iphone 4_the apple logo turning on and off when connected  to my laptop.
    I can't switch it on when disconnected from ma laptop

    Perhaps your battery is bad.
    Have you had problems with decreasing battery life in the past?

  • Portg R600-11B - Problems with switching displays

    Hi,
    I've a problem with a Portg R600-11B running Windows 7 64bit.
    The computer is nomally plugged in a docking station that is connected with a DVI monitor. Here I can select with <FN> + <F5> between the different display modi "internal" / "internal" + "DVI" / "DVI".
    When I unplug the computer from the docking station and connect it to a beamer via VGA I can't switch the display. I only get "internal". Only after a system-reboot <FN> + <F5> works with an external VGA monitor.
    When switching back to the docking station with the DVI monitor it's the same: I only get the internal display. Only after a system-reboot <FN> + <F5> works.
    What can I do? I have the latest Microsoft Updates for Windows and Office (2003) and the latest "Value added package" from the download page installed.
    Regards,
    Axel Martin

    Try updating:
    * BIOS
    * Display Driver
    * Mobile Extensions / TVAP
    Go to the Toshiba website to download these files.

  • Problem with switch-statement & ä, ö, ü

    Hi all,
    I am doing this Java online tutorial right now and have a problem with one of the exercises. Hopefully you can help me:
    I have to write a program that determines the number of consonants, vowels, punctuation characters, and spaces in an input line. I found a solution, but have two questions about it:
    •     I’m unable to calculate the amount of umlauts (ä, ö, ü). Somehow the program doesn’t recognize those characters. Why?
    •     In general I’m not very happy with this huge list of “cases”. How would you solve a problem like this? Is there a more convenient/elegant way?
    Thanks in advance!
    Write a program that determines the number of consonants, vowels, punctuation characters, and spaces in an input line.
    Read in the line into a String (in the usual way). Now use the charAt() method in a loop to access the characters one by one.
    Use a switch statement to increment the appropriate variables based on the current character. After processing the line, print out
    the results.
    import java.util.Scanner;
    class Kap43A1
      public static void main ( String[] args )
        String line;
        char letter;
        int total, countV=0, countC=0, countS=0, countU=0, countP=0;
        Scanner scan = new Scanner(System.in);
        System.out.println( "Please write a sentence " );
        line = scan.nextLine();
        total=line.length(); //Gesamtanzahl an Zeichen des Satzes
        for (int counter=0; counter<total; counter++)
          letter = line.charAt(counter); //ermitteln des Buchstabens an einer bestimmten Position des Satzes
          switch (letter)
            case 'A': case 'a':
            case 'E': case 'e':
            case 'I': case 'i':
            case 'O': case 'o':
            case 'U': case 'u':
              countV++;
              break;
            case 'B': case 'b': case 'C': case 'c': case 'D': case 'd': case 'F': case 'f': case 'G': case 'g': case 'H': case 'h':
            case 'J': case 'j': case 'K': case 'k': case 'L': case 'l': case 'M': case 'm': case 'N': case 'n': case 'P': case 'p':
            case 'Q': case 'q': case 'R': case 'r': case 'S': case 's': case 'T': case 't': case 'V': case 'v': case 'W': case 'w':
            case 'X': case 'x': case 'Y': case 'y': case 'Z': case 'z':
              countC++;
              break;
            case ' ':
              countS++;
              break;
            case ',': case '.': case ':': case '!': case '?':
              countP++;
              break;
            case 'Ä': case 'ä': case 'Ö': case 'ö': case 'Ü': case 'ü':
              countU++;
              break;
        System.out.println( "Total amount of characters:\t" + total );
        System.out.println( "Number of consonants:\t\t" + countC );
        System.out.println( "Number of vocals:\t\t" + countV );
        System.out.println( "Number of umlauts:\t\t" + countU );
        System.out.println( "Number of spaces:\t\t" + countS );
        System.out.println( "Number of punctuation chars:\t" + countP );
    }

    WRE wrote:
    •In general I’m not very happy with this huge list of “cases”. How would you solve a problem like this? Is there a more convenient/elegant way?I've been doing this a lot lately myself evaluating documents with 20 or so million words. Few tips:
    1. Regular expressions can vastly reduce the list of cases. For example you can capture all letters from a to z or A to Z as follows [a-zA-Z]. To match a single character in a String you can then make use of the Pattern and Matcher classes, and incorporate the regular expression. e.g.
      //Un-compiled code, may contain errors.
      private Pattern letterPattern = Pattern.compile("[a-zA-Z]");
      public int countNumberOfLettersInString(final String string) {
        int count = 0;
        Matcher letterMatcher = letterPattern.matcher(string);
        while(letterMatcher.find()) {
          count++;
        return count;
      }2. As mentioned above, Sets are an excellent choice. Simply declare a static variable and instantiate it using a static initializer block. Then loop over the String to determine if the character is in the given set. e.g.
      //Un-compiled code, may contain errors.
      private static Set<Character> macrons = new HashSet<Character>();
      static {
        macrons.add('ä');
        macrons.add('ö');
        macrons.add('ü');
      public int countNumberOfMacronsInString(final String string) {
        int count = 0;
        for(char c : string.toCharArray()) {
          if(macrons.contains(c) {
            count++;
        return count;
      }Mel

  • Memories problem with switches

    Hi all,
    We have a memories problem with the Switches since we deploy ISE3315.
    When the Switch memories are full(90%) Posture does not work correctly.
    Can this memories Problem can be cause by the authentication messages send by the Switches to ISE?

    Have you enabled http(s) server? That's required.

  • A problem with Switch HP 5500 EI

    hi everybody,
    I have a problem with SW HP 5500 EI J377A. I format flash of switch. After reset, the switch can't run normal, it has norfitication as: "No correct default file to boot!", and boot menu as attach picture
    I've search, but i can't have a solution to troubleshoot this problem
    Can you help me please, thanks alot.

    Hi,
    I think you'll be better off in a HP forum or HP support.
    http://h30499.www3.hp.com/t5/Comware-Based/A5120-No-correct-default-file-to-boot/td-p/6032539#.UkvVanLm7fI
    Regards
    Rolf

  • Hi I have problem with switch on my ipad.I tried by itunes but nothing happend.What I have to do?Ipad is only 3 months old :(

    hi. Could someone help me!!!   I have problem with stwich on my ipad. he is only 3 months old. I tried by itunes but still dont help. is the problem number 9.please help me!!!!

    My ipad is on DFU mode I conected with itunes. Itunes see my ipad. He restoring the software on ipad and then nothing happed. I see just logo apple. Could you help me what I have to do?

  • Having problem with switch statement..please help

    here my question :
    GUI-based Pay Calculator
    A company pays its employees as executives (who receive a fixed weekly salary) and hourly workers (who receive a fixed hourly salary for the first 40 hours they work in a week, and 1.5 times their hourly wage for overtime worked).
    Each category of employee has its own paycode :
    ?     Paycode 1 for executives
    ?     Paycode 2 for hourly workers
    Write a GUI-based application to compute the weekly pay for each employee. Use switch to compute each employee?s pay based on that employee?s paycode.
    Use CardLayout layout manager to display appropriate GUI components. Obtain the employee name, employee paycode and other necessary facts from the user to calculate the employee?s pay based on the employee paycode:
    ?     For paycode 1, obtain the weekly salary.
    ?     For paycode 2, obtain the hourly salary and the number of hours worked.
    You may obtain other information which you think is necessary from the user.
    Use suitable classes for the GUI elements. (You can use javax.swing package or java.awt package for the GUI elements.)
    here my code so far :
    import java.awt.;*
    import java.awt.event.;*
    import javax.swing.;*
    *public class PayrollSystem implements ItemListener {*
    JPanel cards, JTextField, textField1, JLabel, label1;
    final static String EXECUTIVEPANEL = "1.EXECUTIVE";
    final static String HOURLYPANEL = "2.HOURLY WORKER";
    public void addComponentToPane(Container pane)
    *//Put the JComboBox in a JPanel to get a nicer look.*
    JPanel comboBoxPane = new JPanel(); //use FlowLayout
    JPanel userNameAndPasswordPane = new JPanel();
    *// User Name JLabel and JTextField*
    userNameAndPasswordPane.add(new JLabel("NAME"));
    JTextField textField1 = new JTextField(25);
    userNameAndPasswordPane.add(textField1);
    *String comboBoxItems[] = { EXECUTIVEPANEL, HOURLYPANEL };*
    JComboBox cb = new JComboBox(comboBoxItems);
    cb.setEditable(false);
    cb.addItemListener(this);
    comboBoxPane.add(cb);
    *//Create the "cards".*
    JPanel card1 = new JPanel();
    card1.add(new JLabel("WEEKLY SALARY"));
    card1.add(new JTextField(6));
    card1.add(new JLabel("TOTAL PAY"));
    card1.add(new JTextField(8));
    card1.add(new JButton("CALCULATE"));
    JPanel card2 = new JPanel();
    card2.add(new JLabel("HOURLY SALARY"));
    card2.add(new JTextField(6));
    card2.add(new JLabel("TOTAL HOURS WORK"));
    card2.add(new JTextField(8));
    card2.add(new JButton("CALCULATE"));
    *//Create the panel that contains the "cards".*
    cards= new JPanel(new CardLayout());
    cards.add(card1, EXECUTIVEPANEL);
    cards.add(card2, HOURLYPANEL);
    pane.add(comboBoxPane, BorderLayout.PAGE_START);
    pane.add(userNameAndPasswordPane, BorderLayout.CENTER);
    pane.add(cards, BorderLayout.PAGE_END);
    public void itemStateChanged(ItemEvent evt)
    CardLayout cl = (CardLayout)(cards.getLayout());
    cl.show(cards, (String)evt.getItem());
    ** GUI created*
    *private static void createAndShowGUI() {*
    *//Make sure we have nice window decorations.*
    JFrame.setDefaultLookAndFeelDecorated(true);
    *//Create and set up the window.*
    JFrame frame = new JFrame("GUI PAY CALCULATOR");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    *//Create and set up the content pane.*
    PayrollSystem demo = new PayrollSystem();
    demo.addComponentToPane(frame.getContentPane());
    *//Display the window.*
    frame.pack();
    frame.setVisible(true);
    *public static void main(String[] args) {*
    *//Schedule a job for the event-dispatching thread:*
    *//creating and showing this application's GUI.*
    *javax.swing.SwingUtilities.invokeLater(new Runnable() {*
    *public void run() {*
    createAndShowGUI();
    HOW CAN I PERFORM THE SWITCH STATEMENT INSIDE THIS CODE TO LET IT FULLY FUNCTIONAL..?
    I MUST PERFORM THE SWITCH STATEMENT LIKE IN THE QUESTION..
    PLEASE HELP ME..REALLY APPRECIATED...TQ

    hi
    A switch works with the byte, short, char, and int primitive data types. So you can simply give the
    switch (month) {
                case 1: 
                            System.out.println("January");
                            break;
                case 2:  {
                            System.out.println("February");
                             break;
                case 3: {
                              System.out.println("March");
                              break;
                             }where month controlls the flow
    moreover u can go to http://www.java-samples.com/java/free_calculator_application_in_java.htm
    for reference, just replace the if statement with switch with correct syntax

  • Problems with switching language (Mac os)

    Hello.
    I have Mac os 10.6.8 and two languages in input source - US and Russian.
    I have a sample application build with sdk 4.5.1 Air 3. When I using this application russian language is always disabled. It enabled only if I'm focused on text input components.
    When I lost focus in switches back to US. It very incomvinient to my users always switching back to Russian.
    In earlier Air versions everything worked fine.

    And i caught this exception
    Error #2063
              at flash.system::IME$/set enabled()
              at mx.managers::FocusManager/focusInHandler()
              at flash.display::Stage/set focus()
              at mx.core::UIComponent/setFocus()
              at spark.components::DataGrid/setFocus()
              at mx.managers::FocusManager/activateWindowHandler()
              at flash.events::EventDispatcher/dispatchEventFunction()
              at flash.events::EventDispatcher/dispatchEvent()
              at mx.core::UIComponent/dispatchEvent()
              at spark.components::WindowedApplication/nativeWindow_activateHandler()
    There are no problems in AIR 3.7 and lower

  • Java 3D a problem with switching appearances

    I'm writing an application which allows to change primitive objects' ( sphere, box and cone- objects are changed with JComboBox) properties via user interface. It has a few panels each for different attributes group ( on the basis of Appearance class ). There is one main appearance which attributes are adjusted in the user interface, there are also three default appearances, one for each object. When I want to change the appearance of some object I just apply the main appearance to the desired object and change the values of attributes. And there's my problem. When I switch between the objects the main appearance is applied to each of them and so are the changes made after the switching. I tried to fix it in some ways.
    1. I tried going back to the default appearance after changing another object. For instance.. I chose sphere and operated on it.. then I switch to cone so I change sphere appearance back to its default and apply the main appearance to cone. But it obviously didn't work as I want to keep changes made on every object ( here: sphere).
    2. I tried to put the values of main appearance in the default sphere's appearance:
    sphereAppearance = mainAppearance;
    sphere.setAppearance(sphereAppearance); // previously the mainAppearance was set
    But it also didn't work. The changes are made on every choosen object.
    3. I also tried to apply attributes of the main appearance to the default appearance of the object:
    boxAppearance.setPointAttributes(mainAppearance.getPointAttributes());
         boxAppearance.setLineAttributes(mainAppearance.getLineAttributes());
    But it turned out that getPointAttributes() and getLineAttributes() and so on return the object of current Point, Line..... Attributes object which were defined:
    PointAttributes pointAttributes = new PointAttributes();
         LineAttributes lineAttributes = new LineAttributes();
    and attached to te mainAppearance:
    mainAppearance.setLineAttributes(lineAttributes);
    mainAppearance.setPointAttributes(pointAttributes);
    So it also ended in changes being made on every choosen object (and i wanted to change only one ).
    If you have any idea how to make a copy of mainAppearance that won't be affected by changes made on
    mainAppearance please help me ;)

    ac09
    Please do not request off-forum communication by email. Discussions may be kept on the forum.
    I'm blocking your post.
    db
    ac09 wrote:
    dear friend...
    Most probably YOU HAVE NOT DECLARED THE CLASS AS PUBLIC if rest are right...
    So make it....
    & there is nothing like brand new....
    contact : [email address removed]

  • Problem with switching tabs in top level navigation

    Hi,
    I've created two tabs (based on two roles) in the portal top level navigation menu. When clicking the first one it opens as it should. Then when clicking on the second tab it will not open, instead the first tab open up again, it sort of switches back automatically.
    Does anyone have any expericene with this type of problem?
    Best regards, Olof Trönnberg

    Hi George
    On startup of the role an iview was called which opened a gif file stored in the KM. This iview wasn't added to any page so I basically did just that; added it to a page. Now the problem seems to have gone away!
    Thanks!

  • MSI R9 270x and problems with switching power-saving modes

    hi,I bought this video card but now I began to twitch screen sometimes when switching video card power saving modes
    it all happens in a game, or at the sites but not on the desktop
    how to disable power saving mode so that it always runs at maximum frequency?
    or how to disable Perf Level 0

    Ok, sorry about that.
    Currently seem to have a Grey Screen whenever I boot the desktop with the graphics card installed.
    1. I tried system restore to see if it was a program causing the grey screen, but same problem.
    2. Tried installing the cd version of the AMD drivers same problem.
    3. Installed the latest version of the driver, as well as, beta version same problem.
    4. Removed the graphics card and put it back in booted up, same problem.
    5. Also tried the Molex Cables that came in the box to different power supply on the PSU, same problem.
    PSU:
    Main Board: MSI Z77A-G45
    Bios Version:Version: V2.12, (9/29/2013)
    Video Card Driver Version:13.250.18.0
    Video Card BIOS Version:113-C6310100-X15:
    Video Card: msi R9 270X Hawk
    Video Card S/N: 602-V303-02SB1309098658
    PSU: 650W TX650 V2 PSU 80 PLUS Bronze  
    12v rail Rating of listed PSU: +12V_53A, -12V_0.8A
    CPU: Intel Core i5-3570K CPU @ 3.40GHz, LGA 1155, 77W
    Memory: Corsair Vengeance 16GB (2x8GB) DDR3 1600 MHz (PC3 12800)
    SSD/ HDD: 120GB SSD, 1TB HDD, 150GB HDD
    CPU COOLER: Cooler Master Hyper 212 EVO
    OC:No
    Operating System: Win 8 Pro 64bit

  • Problem with switching KeyListeners with different functions

    I have two KeyListener objects; one that listens for keyPressed events and another that listens for keyTyped events. I have a JFrame that, depending on the situation, may need one or the other, and often switches between the two. When I switch from the "keyPressed" KeyListener to the "keyTyped" KeyListener, there is a problem if the event is both a keyPressed type event and a keyTyped type event. To illustrate the point, say the KeyTyped listener is for an input field. Let's say the user has to press the "G" key to get to the input field, and when he or she presses "G" the JFrame will first remove the "keyPressed" listener and then add the "keyTyped" listener for the input field. This would seem to be a safe order to go about things; however, when the input field displays, there is a "g" already in the field. What should I do to avoid this kind of situation?

    set the text with yourtexfield.setText(null) method for text field after removing the listener

Maybe you are looking for

  • Touchpad in Cinnamon stops working

    So this has happened twice now. I got arch setup on my new Acer Aspire 1830T and everythings great. I'm trying out cinnamon as my desktop environment and I'm loving it. Here's the problem, after a few days, my trackpad just stop working all together.

  • New General Ledger - Document splitting

    Suppose a vendor invoice of 1,000 EUR assigned to 2 cost centers, CC1 and CC2 (500 EUR on each). The corresponding profit centers are PC1 and PC2. Entry view: PK Acct Amt CC PC 31 Vendor -1000 40 Charges +500 CC1 PC1 40 Charges +500 CC2 PC2 As a resu

  • Problem Joining JDBC theme to XML NSDP file

    I've created a basic map of Germany with different layers for regions etc. I've then added a dynamic JDBC theme using the following code var baseQuery= "select geometry, name from world_sample.world_city_metropolis where iso_country_code = 'DEU'"; va

  • Help: DDIC Lock object

    Hi All, I have doubt about lock object, when we create lock object ENQUEUE_OBJ AND DEQUEUE_OBJ also gets created but what about transporting it? should we transport it saparately or automatically its get transported? Thx.

  • Connection closed message by RFC function module.

    Hi experts, I have an RFC function module where I have no own exception defined. I use 'standard' ones. EXCEPTIONS   communication_failure = 1 MESSAGE ls_proto-message   system_failure        = 2 MESSAGE ls_proto-message Inside this FM I do update of