Results 1 to 14 of 14
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post NumberFormatException

    i am trying to store a value to a file. this value is very small and i format it using DecimalFormat class. For instance my value is
    1.967069154774973E-9
    and i format it using this constructor
    DecimalFormat myVal = new DecimalFormat("0.0000E0");
    The formatted value is stored in a file
    When i try to retrieve this value i get the NumberFormatException:(

    How can i deal with this kind of a problem??
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Hi Manfizy,
    Send the complete code.This single line will not help to give the solution.
    -Regards
    Ramya
    Ramya:cool:

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Manfizy View Post
    i am trying to store a value to a file. this value is very small and i format it using DecimalFormat class. For instance my value is and i format it using this constructor
    The formatted value is stored in a file
    When i try to retrieve this value i get the NumberFormatException:(

    How can i deal with this kind of a problem??

    Ok, once you write the value, open the file and see anything wrong with the formating first.

  4. #4
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    i am trying to store a value to a file. this value is very small and i format it using DecimalFormat class. For instance my value is
    Quote:
    1.967069154774973E-9

    and i format it using this constructor
    Quote:
    DecimalFormat myVal = new DecimalFormat("0.0000E0");

    The formatted value is stored in a file
    When i try to retrieve this value i get the NumberFormatException
    Excuse me pple, i would like to make a correction here. The formatted value is stored in a table and not a file as i had stated earlier. i get the values in a file, format them and display then in a certain table. It displays on the table the way i want it to.
    I get the error when i try to access the values in the table

    Below is my code for that section :

    Java Code:
    public void ConcentrationProfiles() {
    
        int k;
        int rCount = Temp.getRowCount();
         //Loop to initialize Array size
     for ( k = 0; k < rCount; k++){
         String power_t = (String)Temp.getValueAt(k,1);
            if (power_t == null){
                break;   }
              }
      LOOP = new double[k];//Array size
     
     final XYSeries series2 = new XYSeries("Iodine Conc.");
        
     //Iodine Concentration profile
    
    double x_axis_val,y_axis_val;
    for (k = 0; k < LOOP.length; k++) {
       int time_t = (Integer)Temp.getValueAt(k,0);
           x_axis_val = time_t;
           
       //double iodConc =(Double)Temp.getValueAt(k, 2);
        String iodConc =(String)Temp.getValueAt(k, 2);
        double y_value =Double.valueOf(iodConc.trim()).doubleValue();
    
         y_axis_val =y_value;
    
    series2.add(x_axis_val, y_axis_val);
    }
    final XYSeriesCollection dataset = new XYSeriesCollection();
    //dataset.addSeries(series1);
    dataset.addSeries(series2);
    
    chart  = ChartFactory.createXYLineChart("Xenon & Iodine Concentration ",
         "Time(Mins)", "Xenon & Iod (E-09)",(XYSeriesCollection) dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartPanel frame1 = new ChartPanel(chart,true,true,true,true,true);
       frame1.addMouseListener(frame1);//ddChartMouseListener(chartMouseMoved(chartMouseEvent event));
    
    ConcentrationGraph.setLayout(new BorderLayout());
     ConcentrationGraph.add(frame1);
      ConcentrationGraph.validate();
    }
    here is the problem
    String iodConc =(String)Temp.getValueAt(k, 2);
    double y_value =Double.valueOf(iodConc.trim()).doubleValue();
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Manfizy,
    In the below lines what u mentioned

    String iodConc =(String)Temp.getValueAt(k, 2);
    double y_value =Double.valueOf(iodConc.trim()).doubleValue();

    Have u tried to print iodConc.Might be "" or invalid number value .Check it once.Then only it will throw "NumberFormatException"

    -Regards
    Ramya
    Ramya:cool:

  6. #6
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    Hi Ramya,
    it prints the value as it is displayed in the table
    Grapph value --->5,8333E-9
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  7. #7
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Manfizy,
    Double.value expects pure numbers.It can't identify exponents.Use BigDecimal or Decimalformat.

    -Regards
    Ramya
    Ramya:cool:

  8. #8
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Use like this
    String iodConc =(String)Temp.getValueAt(k, 2);
    double y_value =new BigDecimal(iodConc.trim()).doubleValue()
    Ramya:cool:

  9. #9
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    :mad:Still getting NumberFormatException
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Might be "," is there .Check it once
    Ramya:cool:

  11. #11
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    ";" is in place and again am using an IDE that can tell me when something is missing:confused:
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  12. #12
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    I believe Ramya was indicating that there might be a ',' in the number itself, not in your source code. ie 1,000.625

    I believe the DecimalFormat class can handle that though.

    Grapph value --->5,8333E-9
    That statement is a little ambiguous. Is that "5,8333E-9" the value of iodConc?

    Are the numbers supposed to have decimals? The one above doesn't.

  13. #13
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    @ mr. Beans, yep the number is supposed to have decimal places and that´s why i formatted it. am using OS that is in German and MAYBE that is why the decimal point automatically appear as ","
    This appears after formatting and am tempted to thinks its somekind of locale o something:p
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by Manfizy View Post
    Java Code:
       //double iodConc =(Double)Temp.getValueAt(k, 2);
        String iodConc =(String)Temp.getValueAt(k, 2);
        double y_value =Double.valueOf(iodConc.trim()).doubleValue();
    here is the problem
    You're formatting the values from the file using DecimalFormat, in a specific format as given in your OP. You are then using valueOf() to convert this format into a double. Unless the format you have used is valid for valueOf() it won't work. Why don't you use the DecimalFormat String you've defined and parse iodConc?

    In general, if you do something using one technique, you should use the reverse of that technique to get back to where you started.

Similar Threads

  1. NumberFormatException raised
    By venkatallu in forum New To Java
    Replies: 1
    Last Post: 06-02-2009, 09:27 PM
  2. XML JDOM XPATH NumberFormatException
    By Jazzperson in forum Advanced Java
    Replies: 3
    Last Post: 03-08-2009, 08:15 PM
  3. NumberFormatException problem
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 02-06-2009, 07:39 AM
  4. Error: NumberFormatException
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:41 AM
  5. java.lang.NumberFormatException: null
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •