Results 1 to 14 of 14
Thread: NumberFormatException
- 07-08-2009, 10:23 AM #1
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
and i format it using this constructor1.967069154774973E-9The formatted value is stored in a fileDecimalFormat myVal = new DecimalFormat("0.0000E0");
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:
- 07-08-2009, 11:33 AM #2
Hi Manfizy,
Send the complete code.This single line will not help to give the solution.
-Regards
RamyaRamya:cool:
- 07-08-2009, 12:36 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 07-08-2009, 01:55 PM #4
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 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
I get the error when i try to access the values in the table
Below is my code for that section :
here is the problemJava 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(); }String iodConc =(String)Temp.getValueAt(k, 2);
double y_value =Double.valueOf(iodConc.trim()).doubleValue();We Learn Through Mistakes..,
Manfizy:rolleyes:
- 07-08-2009, 02:11 PM #5
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
RamyaRamya:cool:
- 07-08-2009, 02:35 PM #6
Hi Ramya,
it prints the value as it is displayed in the tableGrapph value --->5,8333E-9We Learn Through Mistakes..,
Manfizy:rolleyes:
- 07-08-2009, 02:45 PM #7
Manfizy,
Double.value expects pure numbers.It can't identify exponents.Use BigDecimal or Decimalformat.
-Regards
RamyaRamya:cool:
- 07-08-2009, 02:56 PM #8
Use like this
String iodConc =(String)Temp.getValueAt(k, 2);
double y_value =new BigDecimal(iodConc.trim()).doubleValue()Ramya:cool:
- 07-08-2009, 03:15 PM #9
:mad:Still getting NumberFormatException
We Learn Through Mistakes..,
Manfizy:rolleyes:
- 07-08-2009, 03:30 PM #10
Might be "," is there .Check it once
Ramya:cool:
- 07-08-2009, 03:35 PM #11
";" is in place and again am using an IDE that can tell me when something is missing:confused:
We Learn Through Mistakes..,
Manfizy:rolleyes:
- 07-08-2009, 06:43 PM #12
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.
That statement is a little ambiguous. Is that "5,8333E-9" the value of iodConc?Grapph value --->5,8333E-9
Are the numbers supposed to have decimals? The one above doesn't.
- 07-08-2009, 09:41 PM #13
@ 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:pWe Learn Through Mistakes..,
Manfizy:rolleyes:
- 07-09-2009, 11:59 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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
-
NumberFormatException raised
By venkatallu in forum New To JavaReplies: 1Last Post: 06-02-2009, 09:27 PM -
XML JDOM XPATH NumberFormatException
By Jazzperson in forum Advanced JavaReplies: 3Last Post: 03-08-2009, 08:15 PM -
NumberFormatException problem
By bluebarca in forum New To JavaReplies: 1Last Post: 02-06-2009, 07:39 AM -
Error: NumberFormatException
By coco in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:41 AM -
java.lang.NumberFormatException: null
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-05-2007, 05:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks