Casting string as int always makes it zero?

Hi
I've had to make
_myID = event.selectedRow.getData("my_id");
into
_myID= event.selectedRow.getData("my_id") as int;
so that it stops causing a warning when my buddy loads it into FlashDevelop (I'm working in Pro)
Since then, every myID becomes 0. eg if event.selectedRow.getData("request_id") contains "29" it turns 29 into into zero.
What should I do so that "29" becomes 29?
Thanks for taking a look.

You can also use parseInt and parseFloat, which have the advantage of letting you check for isNaN if the cast fails (but the variable type needs to be Number for this to work--I don't think int can be NaN).

Similar Messages

  • How can i cast array of string to int ?

                       while(st.hasMoreTokens()){
                                  test[count] = st.nextToken();
                                  count++;
                          }Since token deal with string, i have to pass them into String of array, but how can i convert all of them to int to perform arithmetic operation?

         public static void main (String[] args) throws IOException{
               DataInputStream dis = null;
                 String dbRecord = null;
                 int tokenCount = 0;
                 int numOfQuestion = 0;
                 int questionnAireNum = 0;
                 int postCode = 0;
                 int age = 0;
                 int gender = 0;
                 String [] response = new String[10];
                    File f = new File("polldata.txt");
                    FileInputStream fis = new FileInputStream(f); 
                    BufferedInputStream bis = new BufferedInputStream(fis); 
                    dis = new DataInputStream(bis);
                    // read the first record of the database
                    while ( (dbRecord = dis.readLine()) != null) {
                       StringTokenizer st = new StringTokenizer(dbRecord, ",");
                       tokenCount = st.countTokens();
                       numOfQuestion = tokenCount-4;
                       String rquestionNum = st.nextToken();
                       questionnAireNum = Integer.parseInt(rquestionNum);
                       String rpostCode = st.nextToken();
                       postCode = Integer.parseInt(rpostCode);
                       String rAge  = st.nextToken();
                       age = Integer.parseInt(rAge);
                       String rGender = st.nextToken();
                       gender = Integer.parseInt(rGender);
                       for(int i=0; i<numOfQuestion;i++){
                            response[i] = st.nextToken();
                       }hi how come when i cast the string as int it prompt me error as shown below ? I wonder what causes this because this is normally how i cast string to int, somehow it won work this way with token.
    Exception in thread "main" java.lang.NumberFormatException: For input string: " 3"
         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
         at java.lang.Integer.parseInt(Integer.java:447)
         at java.lang.Integer.valueOf(Integer.java:553)
         at test.main(test.java:43)

  • 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"));

  • Kinda urgent    please help pass strings to doubles and strings to ints

    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a double

    cupofjava666 wrote:
    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a doubleThink he means blank.
    Check the Wrapper classes (Double, Integer) in the api.
    parseInt() parseDouble() both take a string and return a primitive.
    String s = null;
    if(s == null) should do the trick!
    Regards.
    Edited by: Boeing-737 on May 29, 2008 11:08 AM

  • Problem with String to Int conversion

    Dear Friends,
    Problem with String to Int conversion
    I am having a column where most of the values are numeric. Only 4 values are non numeric.
    I have replaces those non numeric values to numeric in order to maintain the data type.
    CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END
    This comes the result as down
    Grade
    _0_
    _1_
    _10_
    _11_
    _12_
    _13_
    _14_
    _15_
    _16_
    _17_
    _18_
    _19_
    _2_
    _20_
    _21_
    _22_
    _23_
    _24_
    _3_
    _4_
    _5_
    _6_
    _7_
    _8_
    _9_
    Refresh
    Now I want to convert this value to numeric and do some calculation
    So I changed the formula as below
    cast (CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END as INT)
    Now I get the following error
    View Display Error
    _     Odbc driver returned an error (SQLExecDirectW)._
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
    SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
    Refresh
    Could anybody help me
    Regards
    Mustafa
    Edited by: Musnet on Jun 29, 2010 5:42 AM
    Edited by: Musnet on Jun 29, 2010 6:48 AM

    Dear Kart,
    This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
    I have done the code like following and it works fine
    Thanks again for your support
    Regards
    Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int)

  • Checking a value...String OR int

    checking a value...String OR int
    how to check a given value whether it is a String OR int
    if(jTextField1.getText()...) is a String
         System.out.println("String");
    else //if it an int
         System.out.println("int");
    How can i check this...
    pls,tell.

    getText of JTextField ALWAYS returns a String.
    You can do this to see if it could be interpreted as an int:
    String theText = jTextField1.getText();
    try
       int theInt = Integer.parseInt(theText);
       System.out.println("int");
    catch (NumberFormatException ex)
       System.out.println("String");
    }If it isn't in a form that can be parsed as an int, you will get an exception and the catch block will get executed.

  • Upgrade os v4.5 BB curve 8310 to higher compatible os & file free always goes to zero byte

    Hi all,<br>Let me introduce myself first, my name is hasya from Indonesia, I am using BB curve 8310 with os v4.5.0.124, There are 2 Things would like to ask for looking for solve/solutions as follow:<br>1. Can I upgrade my BB curve 8310 os v4.5 To higher compatible os?kindly please let me know how to do it and where I can get that software / higher os?<br>2. My file free always goes to zero byte so make my bb is hank or not responding, I already run memory cleaner from BB but can not solve that problem,I always do hard reset (battery pulled out) to get more file free, kindly please let me know how to maintain or keep my file free is not going to zero byte, and please let me know if there is best software can solve it
    Solved!
    Go to Solution.

    S 4.5.0.188 is the highest and latest available release for the 8310.
    Here are directions and the download.
    http://www.blackberryforums.com/general-8300-series-discussion-curve/236833-latest-os-8310-4-5-0-313...
    Turn off your memory cleaner, it is worthless to your situation and does NOT clear additional memory for your device, it just wastes battery and resource, and ONLY cleans already deleted memory to a high secure government specification. Nice for the FBI, CIA, drug and p0rn dealers, worthless for you.
    For low memory issues:
    First thing? Check the File Free at Options > Status, what is the number at File Free?
    Now, leaving the device powered ON, remove the battery of your device, hold a minute, replace and reboot.
    What is the File Free now?
    Read this: http://www.blackberryforums.com/general-blackberry-discussion/116396-managing-your-bb-memory-lost-ca...
    And this: http://www.blackberryforums.com/general-blackberry-discussion/112029-losing-call-logs-sms-emails-opt...
    Additional links to read:
    http://www.blackberry.com/btsc/search.do?cmd=displayKC&docType=kc&externalId=KB15345&sliceId=SAL_Pub...
    http://www.blackberry.com/btsc/search.do?cmd=displayKC&docType=kc&externalId=KB14320&sliceId=SAL_Pub...
    http://www.blackberry.com/btsc/dynamickc.do?externalId=KB14213&sliceId=SAL_Public&command=show&forwa...
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Interesting problems with the 1.2.2 Debugger and String.substring(int)

    Guys/Gals,
    Here's an interesting problem to ponder...
    I define the following values in my class:
    private String descriptorClassName = null;
    private String userObjectClassName = null;
    private String name = null;
    I run the following piece of code as part of the constructor:
    descriptorClassName = this.getClass().getName();
    userObjectClassName = descriptorClassName.substring(0, descriptorClassName.indexOf("Descriptor"));
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1);
    The first line assigns the value of "com.foo.user.UserDataDescriptor" to descriptorClassName.
    The second line assigns the value of "com.foo.user.UserData" to userObjectClassName.
    The third line assigns the value of "UserData" to name.
    As I step through the code, I see the first two values being set, and yet the third value for name is reported by the debugger as:
    "name = null".
    I added a call to log4j, which reports that that value of name has been correctly set!
    This seems to be a result of the String.substing(int) call, as the call to Sring(substring(int, int) is fine.
    Has anyone come accross this one before?
    Does anyone have any workarounds other than:
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1, userObjectClassName.length());
    Cheers all.
    Regards,
    Chris.

    I've been trying to reproduce this problem and it always works perfectly. The debugger tells me that name = "UserData". I'm using JDev 3.2.2 and my project is using JDK1.2.2_JDeveloper. Here's the exact source code I'm trying.
    package com.foo.user;
    public class UserDataDescriptor {
    private String descriptorClassName = null;
    private String userObjectClassName = null;
    private String name = null;
    public UserDataDescriptor() {
    descriptorClassName = this.getClass().getName();
    userObjectClassName = descriptorClassName.substring(0, descriptorClassName.indexOf("Descriptor"));
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1);
    System.out.println("end of constructor");
    public static void main(String[] args) {
    UserDataDescriptor userDataDescriptor = new UserDataDescriptor();
    null

  • How can system ensure to always make replenish qty to Max level?

    Hello,
    I have following query related to posting change in WM
    MAX qty --- 100
    Min qty---      50
    How should I make the stock to Max 100 always when available stock falls below 50?  For ex- if available stock is 49 or 30, or 2 or anything below 50 then system should always replenish it to 100 from Replenishment bin
    I believe when replenished qty in material master is 50 and stock is below 50 then system will replenish 50 qty. How can system ensure to always make replenish qty to Max level?
    Thanks,
    MMC

    Hi,
    Keep the replinish qty as zero in WM2 view of MMR.
    Go to LP21 and see if the requetsed qty is now 100.
    If you keep some qty as replinish qty, the same qty is always proposed as requested qty (TR qty)
    regards
    Shashidhar

  • Strinig.indexOf(String str, Int fromIndex)

    Hello.
    In the API reference manual J2SE 5.0 (and earlyer also),
    "public indexOf(String str, int fromIndex)"
    is discribed such as,
    | Returns the index within this string of the first occurrence of the specified substring,
    | starting at the specified index. The integer returned is the smallest value k for which:
    | k >= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
    I can't understand why str.length() is needed here.
    For example,
    String string = "my beautiful dream";
    String str = "ea";
    int fromIndex = 10;
    in the case, str.ng.indexOf(str, fromIndex) returns 15, the value is what I what to get.
    But,I think the smallest value k for which
    | k >= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
    is 4, isn't it?
    import junit.framework.TestCase;
    * @author phinloda
    * test String.indexOf
    public class IndexOfTest extends TestCase {
         public final void testIndexOf() {
              String targetString = "my beautiful dream";
              String str = "ea";
              int fromIndex = 10;
              int k1 = myIndexOf(targetString, str, fromIndex);
              assertTrue(k1 >= Math.min(fromIndex, str.length()) && targetString.startsWith(str, k1));
              int k2 = targetString.indexOf(str, fromIndex);
              assertTrue(k2 >= Math.min(fromIndex, str.length()) && targetString.startsWith(str, k2));
              assertEquals(k1, k2);
         private int myIndexOf(String targetStr, String str, int fromIndex) {
              for (int n = 0; n < targetStr.length(); n++) {
                   if (n >= Math.min(fromIndex, str.length()) && targetStr.startsWith(str, n)) {
                        return n;
              return -1;
         public static void main(String[] args) {
              junit.textui.TestRunner.run(IndexOfTest.class);
    }lastIndexOf(String str, int fromIndex) is more difficult for me.
    ("this.length()" is right?, but it's nonsense.)

    ("this.length()" is right?, but it's nonsense.)Yes, it should be this.length() and not str.length().
    I don't think it's nonsense because now the empty
    string always gives a non-negative index, e.g.
    "string".indexOf("", 1000) returns 6...perhaps this
    property is useful for some string algorithmsI think it only does this for an empty String, so it would be clearer if the docs said something about returning this.length() if str.length()==0.

  • How to make stock zero after asset consumption?

    Dear all,My scernio is that our business process is cwip all the material is posted either in asset or cost center no inventory is maintained.But for one material user forgot to give account category but in backhand my fico consultant consumped that material agianst asset.But when  checking the STOCK it showing.Pls help how to make stock zero without account effect.It is not possible to reverse as the payment already done.FOR STOCK USING STANDARD TCODE.
    PLS HELP???????????????????????????????

    >
    Tanmoy_mm wrote:
    > Dear all,My scernio is that our business process is cwip all the material is posted either in asset or cost center no inventory is maintained.But for one material user forgot to give account category but in backhand my fico consultant consumped that material agianst asset.But when  checking the STOCK it showing.Pls help how to make stock zero without account effect.It is not possible to reverse as the payment already done.FOR STOCK USING STANDARD TCODE.
    >
    > PLS HELP???????????????????????????????
    how could  your fico consultant consume  that material against asset, without the stock is going down?
    did he do a FI posting only?
    if so, then he has to reverse it and has to post the consumption with a MM movement.

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • String to int conversion

    can n e body tell me how can i convert a String to an int

    always remember to use the try/catch block with thins that throw exceptions
    String gg;
    int in;
    try{  
    gg = "30";
       in = Integer.parseInt(gg);
    catch(NumberFormatException e){ 
      e.printStackTrace();
    }Ant

  • It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is

    It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is there some simple setting out there that will just "make it so?"@

    The video I am watching this guy is just dragging every line to make curves.  And every anchor point is a corner.  He is not switching back and forth between the pen and the anchor points tool, and he is not using the convert points tool.  He draws a curved line and starts another straight line only to curve it with a click and a drag.  It is super efficient, and I could save a world of time if I could figure out what he is doing.

  • I have a mac osX 10.5.8 and i could always make photo books with iphoto , now all of a sudden i cant because i have iphoto version 7.1.5 i have tried countless updates and nothing is working ? help ?

    i have a mac osX 10.5.8 and i could always make photo books with iphoto , now all of a sudden i cant because i have iphoto version 7.1.5 i have tried countless updates and nothing is working ? help ?

    Books are no longer supported with iPhoto '08 (a roughly six yeal old product) - you can purchase an iLife '09 DVD from someplace like Amazon or eBay and install it - iPhoto '09 is still supported this year
    LN

Maybe you are looking for

  • How can i disable a Struts radio based on other element form

    I need some help to do this. I saw some examples in the web to disable a radio button with javascript, and all is right with normal HTML tags. But when i was try to do the same over Struts code it's not function. I show below my code: function habili

  • My ipod froze and make clicking noises

    my ipod video froze and i dont know why. it shows the unhappy ipod symbol but when i got on apple and found what i should do when the symbol shows up and did it, nothing happened. it also makes clicking sounds at random times and when i try to reset

  • Closed Project Window Stays Open

    I have one project out of three where this is a problem.  I can end the project but the window does not close. I am using Captivate 4 and I have gone to preferences and changed end of project to be Close Project. Even at that, the last slide wants to

  • Which is the stable patch level for 2005-B after PL 25.

    Which is the stable patch level for 2005-B for SDK Customization purpose. Previously PL 25 is stable. As now PL 41 is already in market. Anybody knows? regards: Sandy

  • Secondary Sorting

    How do I do a secondary sort?  For example, if I want to sort my songs by Artist and THEN have them alphabetically sorted by song title by each artist?  This used to happen "automatically" in my previous versions of ITunes, but I can not make it work