Combo Box, Converting string to int

The user is able to select the month, year etc for a TimerTask using a combo box.
The problem I have is converting say, "January" to an integer 0 for use to set in a calendar for the date.
The combo box is populated with every month but i cannot link it with the int variable "month" where 0= january, 1- feb etc for use in the TimerTask.
In other words, when the user selects "January" in the combo box i want the integer value for the variable "month" to equal 0, for "Febuary", month to equal 1, "March", month equal 2 etc etc.
Any help would be excellent!!

if January is the first item in the box, February is the second, all the way to December:
month = monthComboBox().getSelectedIndex();

Similar Messages

  • How to convert String to int in JSP?

    Hi,
    I set a session attribute in Servlet and want use it in JSP, How can I convert it to int or Integer?
    the line in my code doesn't work:
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    Thanks in advance.
    Wolf
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    <HTML>
    <HEAD>
    <TITLE>Using the for Statement</TITLE>
    </HEAD>
    <BODY>
    <H1>Using the for Statement</H1>
    <%=session.getAttribute("vehiclequantity") %>;
    <%
    int loopIndex;
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    out.println(quantity);
    for (loopIndex = 1; loopIndex <=2; loopIndex++) {
    out.println("This is iteration number "
    + loopIndex + "<BR>");
    %>
    </BODY>
    </HTML>

    Learning how to read errors and understand them will help you solve your problems quicker by yourself... So lets take a look at the error and classes involved...
    The error says:
    "Cannor Resolve Symbol: method valueOf(java.lang.Object) in the class java.lang.Integer" and gives you line line where the error occurs: Integer quantity = Integer.valueOf(session.getAttribute("vehiclequantity"));
    Now, if we look at the API for the Integer we notice that are are only two valueOf methods: valueOf(java.lang.String s) and valueOf(java.lang.String s, int radix). Not valueOf(java.lang.Object) method.
    Now we look at the getAttribute(java.lang.String name) method of HttpSession we see that the method returns a java.lang.Object. Now, you know you put a java.lang.String into that attribute, but the get method returns an Object. This is because you could have put any object in there, an Integer, a String, or some other class instance. But you know it is a String, so you can cast the returned value to a String, so that you will be calling the valueOf(java.lang.String s) method of Integer with the Object returned from the HtttpSession's getAttribute(java.lang.String name) method:
    Integer quantity = Integer.valueOf((String)session.getAttribute("vehiclequantity"));

  • Converting string to int

    I cannot convert this string to integer.
    int tempI = Integer.parseInt("fdcedfbd", 16);
    it returns a numberFormatException
    but if I do this then there will be no problem.
    int tempI = 0xfdcedfbd
    Can anybody help me with this? Thank you.

    It sounds like the real problem here is that someone is giving you an 8-byte unsigned value represented as a 16-character hexadecimal string, and they want you to convert that into the actual 8 bytes. Are they going to do bit manipulation on it or something?
    If you successfully convert it into a long and they then try to do math with it, they'll run into the sign/overflow problems everyone else has been talking about. If they just want to look at the individual bits then it would make sense to do the conversion into a long.
    You could do something like this:
      private static final String highOrderDigits = "89abcdef";
      public long hexToLong(String hex) {
        // Only process exactly 16-digit strings.
        if (hex.length() != 16) {
          throw new IllegalArgumentException("Expect 16-digit hex value");
        boolean overflow = false;
        // Check for most significant digit > 7, which would
        // cause problem for parseLong.
        int highOrderIndex = highOrderDigits.indexOf(hex.charAt(0));
        if (highOrderIndex > -1) {
          // Clear most-significant bit and set overflow flag.
          overflow = true;
          hex = "" + highOrderIndex + hex.substring(1);
        long result = Long.parseLong(hex, 16);
        if (overflow) {
          // Manually set most significant bit in result.
          result |= 0x8000000000000000L;
        return result;
      }I more or less tested this and it looks to work.

  • Exception thrown trying to convert string to int

    Hey Guys,
    i imported a csv file into my app which i divide using the split() method and put into an array then I divided the array into variables;
    fruit = piece[0];
    price = piece[1];
    unit = piece[2];Now since price has to be a double i converted it into a double;
    price2 = Double.parseDouble(price);which worked grand
    but when i try to convert unit to an integer
    unit2 = Integer.parseInt(unit);i got error
    Exception in thread "main" java.lang.NumberFormatException: For input string: "3
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    so i tried removing white spaces as follows
    target = unit.replace(" ", "");which worked and displayed grand, then i tried converting to int again but the same exception was thrown, can anyone help me with this problem, thanks
    mark

    sorry for the messed up format previously.
    Like you said the unit.replaceAll(" ", ""); did not do the trick, when displayed as a string it looked like 3 was on its own but still did not convert to int. I assume line break or something existed in the csv file like you mentioned earlier as unit was the last word in the csv file.
    when i used unit.trim(); and tried to convert to integer it worked perfectly.
    thanks all for your help,
    Mark

  • Help trying to convert string to int

    Hey im trying to input a string in an applet then turn it into a integer so i can use it any ideas?

    long val = Long.parseLong(string);
    if(val > Integer.MAX_VALUE || val <
    Integer.MIN_VALUE) {
    throw new Error("I don't like you :p");
    int intVal = (int) val;No real need to use parseLong and check explicitly the limits. The check for MIN and MAX is performed implicitely inside Integer.parseInt(string, 10), which is called by both new Integer(string).intValue() and Integer.parseInt(string) . When the check fails, it throws a NumberFormatException.
    The only difference between post#1 and post#2 is that the latter it stores the int value in the internal int data member after the call to Integer.parseInt(string, 10), hence the intValue() subsequent call.

  • Converting string number int o percentage

    Hi. I have a textfield in which it accepts numbers (2.5 or 2.35 or 32.52)
    How am I going to convert it to double and in percentage format( .0025 or .0035 or .003252)
    Thanks
    Please help

    > and just converting it back to string again. I made
    the division but converting it back to string.
    what function do i need to use?
    In Java they're called "methods".
    http://java.sun.com/developer/JDCTechTips/2004/tt1005.html#2
    http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html
    ~

  • Problem converting string to int

    I want to display records of flights from my database with the things that i get from a form...One of them is the number of passengers...the code is shown below;
    " SELECT * FROM flights WHERE kalkis LIKE ? AND inis LIKE ? AND DepartureDate LIKE ? AND NumPass >= ? ";
    Everything comes up right except the NumPass value...i get the ? value by saying;
    sorgulama.setInt(4,Integer.parseInt(request.getParameter("NumPass")));
    But it won't display the values that are >=...Displays nothing...
    Also the NumPass value is "int" type in the database...
    Any idea to solve this...kinda urgent ..

    Log the parameters being used in your application.
    Run the query directly against the database using the parameters your app is using, verify you find something.

  • Converting String to int again...

    telno.addActionListener(this);
    public void actionPerformed(ActionEvent e){
    int x, p, y;
    if(e.getSource()==telno){
    x = Integer.parceInt(telno.getText());
         p = x/10000;
              y = x%10000;
    there's an error 'cannot resolve symbol' when I try to compile.
    Help please, anyone!
    Thanks

    Hi,
    parseInt() and not parceInt() I think.
    Hope it helps
    S�bastien

  • Converting String type to inte type

    Can any one tell me how I can convert an array of Strings into an array of integers??

    it's simple ..... it's like this...
       // some code goes here....
       String num[]={"23", "342", "21", "1"};
        int n[]= new int[num.length];
        for(int i=0; i<num.length; i++)
             n=Integer.parseInt(num[i]); // << -- convert string to int then copied it to int[]
    // rest of your code....

  • Javascript, string to int

    Dear Sir:
    I try to convert string to int in flash javascript:
    temp="120";
    temp2="140";
    temp3=int ( temp );
    but I got a message "int is not a function", can somebody tell me how to do this?
    also, what if I want convert number back to string?
    thanks a lot!

    use:
    temp="120";
    temp2="140";
    temp3=Number ( temp );
    // to convert to a string, use:
    var temp4:String=String(temp3);
    // or
    var temp5:String=temp3.toString();

  • Long strings in combo box

    I have an editable combo box that I'm sticking in a compact spring layout. The problem is if you use a list that contains very long strings (like a long hex string), the combo box sizes itself to fit it and all the other controls are made to be that length as well. Is there a way to stop the control from becoming so long, like a horizontal scroll bar in the list?

    Read this [url http://www.objects.com.au/java/examples/src/examples/SteppedComboBoxExample.java]example
    Here's its [url http://www.objects.com.au/java/examples/swing/SteppedComboBox.do]picture
    ICE

  • COMBO BOX STRING

    Hi all,
    The string displayed in the combo box is in the left side, is there a method to move it to centre.
    without giving spaces before the string in the edit items.
    The image is attached below
    Solved!
    Go to Solution.
    Attachments:
    combo box.JPG ‏5 KB

    Hello Shrekt,
    set the focus to your combo box (mouse click on it) and then change its text properties.
    Attachments:
    Temp.png ‏16 KB

  • Leading Zeroes are lost when convert from string to int

    What I'm trying to do is simple yet the solution has seemed difficult to find.
    I have a system that requires 4 digit numbers as "requisitionNo". The system uses JSPs and accepts the 4 digit number that the user inputs (fyi - duplicate handling is already managed). The input number (rNumber) is of STRING type and in the action (using struts) is converted to an int:
    int requisitionNo = Integer.parseInt(rNumber);At that very line the issue is that when the user inputs a number with leading zeros such as: "0001" the 3 leading zeros are chopped off in the INT conversion. The application validation kicks in and says: "A 4 digit number is required" which is by design. The work around has been that the user has been putting in number that start with 9's or something like that, but this isn't how the system was intended to be used.
    How do I keep the leading zeroes from being lost instead of saving a number "1" to the database how do I keep it saving "0001" to the database? Would I just change everything to STRING on down to the database? or is there another number type that I can be using that will not chop off the leading zeroes? Please provide short code references or examples to be more helpful.

    Yeah, I have to agree here that leading zeroes make no sense. I figured that out when I started to look into this problem. The only requirement that exists is that the user wants it to be a 4 digit number due to some other requirement they have themselves.
    So what I'm gathering from what I've read in the responses thus far is that I should change the validation a bit to look at the STRING for the 4 required digits (which are really 4 characters; maybe I should add CLIENT side numeric validation; currently its doing server side numeric/integer validation; or maybe change up the server side validation instead???) and if they are ALL GOOD then let the application save the int type as it wants to. IE: Let it save "0001" as just "1" and when I come back to DISPLAY this saved number to the user I should append the string of "000" in front of the 1 for display purposes only? Am I understanding everyone correctly?

  • Combo box strings

    I am trying to get some combo boxes to have their entries populated by a text file. I've read many forum entries about the 'strings[]' property, it but it refuses to work for me. I want the combo box to be modifiable by changing entries in a text file.
    Can someone beat this code into submission? I get this error about a GPIB controller needing to be in charge.
    I've included the vi, the text file I want to populate the 'Version Number' combo box and that should be it.
    Tay
    Solved!
    Go to Solution.
    Attachments:
    Event Inspection.zip ‏662 KB
    test.txt ‏1 KB

    On a sidenote, you have some serious coding mistakes. For example look at the following code.
    I would think that the "select" node should act according to the current value of the boolean. WIth your current code, it is very likely that you read the stale value from the property node before the Pass/Fail indicator has received the new value. This is a classic race condition.
    Don't be afraid to branch a wire! The property node is entirely useless and actually is computationally expensive. All you need is a wire. Right? The wire creates a data dependency that ensures correct execution order.
    (See also http://forums.ni.com/ni/board/message?board.id=BreakPoint&view=by_date_ascending&message.id=5178#M51...)
    Message Edited by altenbach on 04-20-2008 01:05 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    RaceConditionAnnotated.png ‏11 KB

  • Cosmetic Glitch when Replacing a Silver Style Combo Box by a String

    As the title says, if you replace a Silver Style Combo Box by a String (same data type), things turn ugly:
    Nothing of the sort happens with the other styles as can be seen above too.

    Hi X
    Yea I get the same behavior in 2012 and 2013. A workaround for this would be to replace the original control or indicator with a non-silver version of the control and then replace that control with the desired silver style control. This seems to work for me.
    Paolo F.
    National Instruments
    Applications Engineer

Maybe you are looking for

  • PDF files are OCR'd and searchable in Preview, but Spotlight is unable to find

    I use Microsoft OneDrive to sync all of my scanned invoices, bills, and receipts for my business to my home and work computers.  At the office I have a newer HP desktop with Windows 8.1 with OneDrive built in natively.  At home I use a 4+ year old iM

  • IMac as screen

    Can I use my early 2008 24" iMac as a screen for a Mac Pro that i'm going to buy??

  • More than 5 base stations...?

    I could use some advicce in setting up what has become a rather complex airport network... Due to the floorplan of our apartment, it's extremely thick (1 meter, stone) walls, the limited location of available sockets and cables (DSL and ethernet) and

  • How can I create cursors within the cursor?

    How can I create cursors within the cursor? Table1 2001 - 2007 data Account_no Account_eff_dt No_account_holder Num Seq_Num Value1 Value2 Table2_Historical (doesn't have Num as a field) 1990 - 2000 data Account_no Account_eff_dt No_account_holder Seq

  • Filter or sort by whether file has develop settings?

    I'm using LR3b but I assume this applies to LR2 as well. I just imported a large number of files - about 20,000 from the last couple of years. Previously these were managed using Expression Media so any star or color ratings did not transfer. Since a