Float value giving exception.

Hi,
I am using a bean for a shopping cart. I used this code
public float getCost()
          Enumeration enum=hashtable.elements();
          String[] tmpItem;
          float totalCost=0.00f;
          while(enum.hasMoreElements())
               tmpItem=(String[])enum.nextElement();
               //totalCost += (Integer.parseInt(tmpItem[3]) * Float.parseFloat(tmpItem[2]));
               totalCost += (Integer.parseInt(tmpItem[3]) * Float.parseFloat(tmpItem[2]));
          return totalCost;
which is giving me this exception.
reported this exception: java.lang.Float: method parseFloat(Ljava/lang/String;)F not found. Please report this to the
administrator of the web server.
java.lang.NoSuchMethodError: java.lang.Float: method parseFloat(Ljava/lang/String;)F not found at
ShopBean.getCost(Compiled Code) at Checkout.doGet(Checkout.java:20) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:715) at
javax.servlet.http.HttpServlet.service(Compiled Code) at
com.sun.server.ServletState.callService(Compiled Code) at
com.sun.server.ServletManager.callServletService(Compiled Code) at
com.sun.server.http.servlet.InvokerServlet.service(Compiled Code) at
javax.servlet.http.HttpServlet.service(Compiled Code) at
com.sun.server.ServletState.callService(Compiled Code) at
com.sun.server.ServletManager.callServletService(Compiled Code) at
com.sun.server.ProcessingState.invokeTargetServlet(Compiled Code) at
com.sun.server.http.HttpProcessingState.execute(Compiled Code) at
com.sun.server.http.stages.Runner.process(Compiled Code) at
com.sun.server.ProcessingSupport.process(Compiled Code) at com.sun.server.Service.process(Compiled
Code) at com.sun.server.http.HttpServiceHandler.handleRequest(Compiled Code) at
com.sun.server.http.HttpServiceHandler.handleRequest(Compiled Code) at
com.sun.server.HandlerThread.run(Compiled Code)
Can any one correct me please?
Thanks
Uma

Hi
Here is the code which will be calling the bean
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Checkout extends HttpServlet
     String itemsvalues,itemno;
     String[] tmpItem;
     public void doGet(HttpServletRequest req,HttpServletResponse res)
          try
               ServletOutputStream sos = res.getOutputStream();
               ShopBean cart =(ShopBean)req.getSession().getValue("cart");
               int totalItems = cart.getNumOfItems();
               System.out.println("totalItems="+totalItems);
               sos.println("<h4>In Checkout.java</h4>");
               float totalCost = cart.getCost();
               sos.println("<h5>Total cost is:"+totalCost+"</h5>");
          catch(Exception e)
               e.printStackTrace();
This class is giving me exceptions
Thanks
Uma

Similar Messages

  • JAVA Float to int exception

    Hi
    I am facing a serious problem after migrating application from oracle 9i to oracle 10g.
    Application was earlier connected with oracle 9i as database after migration to 10g .
    I am facing a problem of float to int exception.
    In database,in table where a column's datatype is defined as number() is treated in java as float but
    *number(p)[p any integer]* is treated as integer in java.
    Earlier when application was on Oracle 9i i never faced this problem but in oracle 10g it is present.
    Can some one help me in this issue.
    What should i do so that data type number() is also treated as integer in java

    You could change your code, or change at table level.
    This is not a trivial task, though:
    SQL> create table t(x number)
    Table created.
    SQL> insert into t values (1)
    1 row created.
    SQL> commit
    Commit complete.
    SQL> alter table t modify x number(10)
    alter table t modify x number(10)
    Error at line 8
    ORA-01440: column to be modified must be empty to decrease precision or scaleYou need something like:
    SQL> alter table t add y number (10)
    Table altered.
    SQL> update t set y = x, x=null
    1 row updated.
    SQL> commit
    Commit complete.
    SQL> alter table t drop column x
    Table altered.
    SQL> alter table t rename column y to x
    Table altered.
    SQL> select * from t
             X
             1
    1 row selected.Regards
    Peter

  • Error in float value

    Hi,
    I am a newbie in JAVA. When I wrote the following code in java it gives me error:
    public class FloatTest
    public static void main(String[] args)
    float f=3.14;
    System.out.println(f);
    It gives me an error saying possible lose of precision. Aren't float value capable of storing values with decimal point?
    Thank you.

    You're giving your float a double literal. If you want to use a float literal, you should append f to the end of the number.
    By the way, there's usually very little reason to use float when a double will do as the precision of double is much greater and the cost of its use is very low if anything at all.

  • How to convert signed ascii hex to float value

    Hi,
    I have a requirement to convert IEEE ascii hex to float value.
    Following code is working for +ve float value but it didn't work for -ve.
    public static float hexToFloat(String str){
              float floatVal= 0.0f;
              int decimalValue =Integer.parseInt(str,16);
              floatVal=Float.intBitsToFloat(decimalValue );
              return floatVal;
    for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
    For the above string I am getting number format exception.
    pls help me.

    The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
    The solution is to use Long.parseLong() instead.
    public static float hexToFloat(String str){
    float floatVal= 0.0f;
    int decimalValue =(int)Long.parseLong(str,16);
    floatVal=Float.intBitsToFloat(decimalValue );
    return floatVal;
    }

  • Union two tables with diffrent count of fields with null and float value

    Hello,
    i want to union two tables, first one with 3 fields and second one with 4 fields (diffrent count of fields).
    I can add null value at end of first select but it does not work with float values in second table. Value form second table is convert to integer.
    For example:
    select null v1 from sessions
    union
    select 0.05 v1 from sessions
    result is set of null and 0 value.
    As workaround i can type:
    select null+0.0 v1 from sessions
    union
    select 0.05 v1 from sessions
    or simple change select's order.
    Is any better/proper way to do this? Can I somehow set float field type in first select?
    Best regards,
    Lukasz.
    WIN XP, MAXDB 7.6.03

    Hi Lukasz,
    in a UNION statement the first statement defines the structure (number, names and types of fields) of the resultset.
    Therefore you have to define a FLOAT field in the first SELECT statement in order to avoid conversion to VARCHAR.
    Be aware that NULL and 0.0 are not the same thus NULL+0.0 does not equal NULL.
    In fact NULL cannot equal to any number or character value at all.
    BTW: you may want to use UNION ALL to avoid the search and removal of duplicates - looks like your datasets won't contain duplicates anyhow...
    Regards,
    Lars

  • Not able to spy objects in ie9 using coded UI Test Builder Spy, giving exception -Interface not registered(Exception from HRESULT:0X....

    Not able to spy objects in ie9 using coded UI Test Builder Spy, giving exception - "Interface not registered(Exception from HRESULT:0X...."
    I am not able to capture any objects of my web application using coded ui recorder. Even though it is a simple html page, coded ui is showing a message  -"Interface not registered(Exception from HRESULT:0X...."
    Please give me solution , why this is hapening. I am having problem with object identification. Even I am not able to identify any object in google.com.
    swapnanil sengupta

    TechnologyName is displaying as "MSAA" . But my application is a Webapplication.If I try to spy the google .com's search field then also TechnologyName is displaying as "MSAA". Is it any configuration issue of vsts codedui.
    swapnanil sengupta

  • How to extract an integer or a float value from a String of characters

    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String
    This is all i have so far:
    String c;
    String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
    while((c=(cr.readLine()))!=null)
    Array[coun]=c;
    it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:55 PM

    badmash wrote:
    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    with the space included
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above StringHuh?
    Not true.
    Anyway why not use string split, split on spaces and grab the last element (which by the format you posted would be your 700.0)
    Then there is the Float.parseFloat method.
    It is easy.
    And another thing why not use a List of Strings if you want to store each line? (And why did you post that code which doesn't really have anything to do with your problem?) Also in future please use the code formatting tags when posting code. Select the code you are posting in the message box and click the CODE button.

  • Rounding up of a float value

    i need some help in rounding up the float value to two places after the decimal point
    i have a value like 25.34446789 and i need to round it up like 25.34

    i tried this function but i am not getting the result
    correctly .if i am using the round () function i am
    getting a value like 55.0 when the original value is
    55.085673.
    i want to get it like 55.09. round to two places
    after the decimal point .is there any other way to do
    it ?How about doing what Chuck said you should do? Give it a try and think about what he wrote. It may actually work.

  • How do i convert a float value to a double value?

    How do i convert a float value to a double value? HELP PLEASE!! im very stuck!! i gota float data type and i need to convert it to a double data type in order to use it in another operation.....
    thank u so much!

    safe dint realise ppl were so arrogant. thanks for the reply but less of the sarcasm!

  • How can i write the floats value in Unitronics vision230 plc using modbus Ethernet

           How can i write the Float value in unitronics Vision230 PLC usinsg modbus ethernet (MB Ethernet Master Query.vi) I  read and write  the 32 bit register,  for e.g i want to write the 23.45 value on 2nd add. of MF. And MF register is 32 bit register. I  read and write  the 32 bit register.
    Narendra.
    Solved!
    Go to Solution.

     Thanks Amit for your solution but i can not use the string to write the value because  MB Ethernet master Query.vi only accepet the integer value its not take string values or any other i.e floats values etc.....otherwise i have  no problem to write or read the 32 bit register values , only problem is that the MB Ethernet master Query.vi only accept the integer value there4 how can write the float value.
    Narendra
    Message Edited by Artemistech on 01-30-2009 11:06 PM

  • Function module to convert float value to data type 'dec'

    Hi experts,
      In a report i need to convert float value to the data type 'DEC'. How to convert it. Is there any function module for this conversion.
    Thanks and Regards,
    Vaibhav Tiwari.

    Hi ..
    We can do like this...
    Data : V_float type F value '12345.67'.
    Data: V_dec type P Decimals 2.
    Write:/ V_float exponent 0. "This will display it like Type P
    or
    Write V_float to V_dec EXPONENT 0.
    Write:/ V_dec.
    reward if Helpful.
    <b></b>

  • Insert float value into ms sql server

    Hi.
    How do I insert a float value into my ms sql db.
    The Code:
    select.setFloat( 4, theForm.getVaerdi() );ERROR:
    "MakeClapetInsertAction.java": Error #: 300 : method setFloat(int, java.lang.Float) not found in interface java.sql.PreparedStatement at line 89, column 12

    setFloat takes a float primitive, not a Float object.
    select.setFloat( 4, theForm.getVaerdi().floatValue() );

  • Client/server RMI app using Command pattern: return values and exceptions

    I'm developing a client/server java app via RMI. Actually I'm using the cajo framework overtop RMI (any cajo devs/users here?). Anyways, there is a lot of functionality the server needs to expose, all of which is split and encapsulated in manager-type classes that the server has access to. I get the feeling though that bad things will happen to me in my sleep if I just expose instances of the managers, and I really don't like the idea of writing 24682763845 methods that the server needs to individually expose, so instead I'm using the Command pattern (writing 24682763845 individual MyCommand classes is only slightly better). I haven't used the command pattern since school, so maybe I'm missing something, but I'm finding it to be messy. Here's the setup: I've got a public abstract Command which holds information about which user is attempting to execute the command, and when, and lots of public MyCommands extending Command, each with a mandatory execute() method which does the actual dirty work of talking to the model-functionality managers. The server has a command invoker executeCommand(Command cmd) which checks the authenticity of the user prior to executing the command.
    What I'm interested in is return values and exceptions. I'm not sure if these things really fit in with a true command pattern in general, but it sure would be nice to have return values and exceptions, even if only for the sake of error detection.
    First, return values. I'd like each Command to return a result, even if it's just boolean true if nothing went wrong, so in my Command class I have a private Object result with a protected setter, public getter. The idea is, in the execute() method, after doing what needs to be done, setResult(someResult) is called. The invoker on the server, after running acommand.execute() eventually returns acommand.getResult(), which of course is casted by the client into whatever it should be. I don't see a way to do this using generics though, because I don't see a way to have the invoker's return value as anything other than Object. Suggestions? All this means is, if the client were sending a GetUserCommand cmd I'd have to cast like User user = (User)server.executeCommand(cmd), or sending an AssignWidgetToGroup cmd I'd have to cast like Boolean result = (Boolean)server.executeCommand(cmd). I guess that's not too bad, but can this be done better?
    Second, exceptions. I can have the Command's execute() method throw Exception, and the server's invoker method can in turn throw that Exception. Problem is, with a try/catch on the client side, using RMI (or is this just a product of cajo?) ensures that any exception thrown by a remote method will come back as a java.lang.reflect.InvocationTargetException. So for example, if in MyCommand.execute() I throw new MySpecialException, the server's command invoker method will in turn throw the same exception, however the try/catch on the client side will catch InvocationTargetException e. If I do e.getCause().printStackTrace(), THERE be my precious MySpecialException. But how do I catch it? Can it be caught? Nested try/catch won't work, because I can't re-throw the cause of the original exception. For now, instead of throwing exceptions the server is simply returning null if things don't go as planned, meaning on the client side I would do something like if ((result = server.executeCommand(cmd)) == null) { /* deal with it */ } else { /* process result, continue normally */ }.
    So using the command pattern, although doing neat things for me like centralizing access to the server via one command-invoking method which avoids exposing a billion others, and making it easy to log who's running what and when, causes me null-checks, casting, and no obvious way of error-catching. I'd be grateful if anyone can share their thoughts/experiences on what I'm trying to do. I'll post some of my code tomorrow to give things more tangible perspective.

    First of all, thanks for taking the time to read, I know it's long.
    Secondly, pardon me, but I don't see how you've understood that I wasn't going to or didn't want to use exceptions, considering half my post is regarding how I can use exceptions in my situation. My love for exception handling transcends time and space, I assure you, that's why I made this thread.
    Also, you've essentially told me "use exceptions", "use exceptions", and "you can't really use exceptions". Having a nested try/catch anytime I want to catch the real exception does indeed sound terribly weak. Just so I'm on the same page though, how can I catch an exception, and throw the cause?
    try {
    catch (Exception e) {
         Throwable t = e.getCause();
         // now what?
    }Actually, nested try/catches everywhere is not happening, which means I'm probably going to ditch cajo unless there's some way to really throw the proper exception. I must say however that cajo has done everything I've needed up until now.
    Anyways, what I'd like to know is...what's really The Right Way (tm) of putting together this kind of client/server app? I've been thinking that perhaps RMI is not the way to go, and I'm wondering if I should be looking into more of a cross-language RPC solution. I definitely do want to neatly decouple the client from server, and the command pattern did seem to do that, but maybe it's not the best solution.
    Thanks again for your response, ejp, and as always any comments and/or suggestions would be greatly appreciated.

  • How to see decimal part of float value?

    How to see only value of decimal part of float value?
    For example, if I have 1.455, i need only to see .455 part.

    Read the floating point value.
    Convert that into a string.
    Use the String's substring and indexOf method to find
    the "." and then cut from there, to the end of the
    string.<sarcasm>
    Really? I'm sure pbrockway already said that but i must be mistaken.
    </sarcasm>

  • Rounding ist wrong for float value (MS SQL 2005)

    Hello
    I have a simple report with a command:
    select num = convert(float, 4.145)
    Field round over "Format Field" or ToText( num, 2) the result is 4.14  -> Wrong
    if  i use Round(num, 2)  result is 4.15 --> OK
    In CR 8.5 result is always correct
    Thx

    I know the problematic of the floating values.
    My big trouble is the inconsistency in the report!
    It can't be that the formula function Round(x,y) show another result than the integrated field-rounding function.
    Also in the formula that ToText(x, y) is different to Round(x,y).
    Following another stupid difference:
    Command.num = 4.145          Result: TRUE
    Command.num - 4.145 = 0     Result: FALSE
    Mathematical it's the same.
    CR8 was consistence, after migration we have different result on our reports!

Maybe you are looking for

  • Download classical report to MS word with OLE

    hi experts,    I have a Classical HR Report that contains profile information of the employee.Now I have to Download the Report to Ms word through OLE . I tried some threads but they were just displaying the static text.I have to download the data fo

  • Need a group by clause for two varibles in one table

    I can't find any way to merge two variables in a group by statement with both vertical and horizobtable output. The statement I got for a vertical output is (in 10gR2): select to_char(d.begin_interval_time, 'YYYY-MM-DD') as Datenumber, w.wait_class a

  • Inspector leaves grey "ghost" panel IN ALL TABS after escape/exit

    when I use inspector (Q) it often leaves grey ghost panel covering about 3 inches of the bottom of my browser window), where the black html panel was - and it is in EVERY OPEN TAB, and if I try to use it again, it will then open a html panel above th

  • TS3694 i have an unknown error 2006. what am i supposed to do?

    I have an unknown error 2006  for my Iphone 5 when I tried doing a recovery mode using itunes. What should I do?

  • Condition not executed in Plan

    Hi, we´ve got a sql statement which looks like that: SELECT BplSegment.SalesOrg, WeeklyBplDataMeta.Line FROM BPLSEGMENT BplSegment LEFT OUTER JOIN BPLDATA WeeklyBplData INNER JOIN BPLDATAMETA WeeklyBplDataMeta ON WeeklyBplDataMeta.PKey=WeeklyBplData.