java.lang.NumberFormatException: For input string: "20.0000"

I an parsing a txt file to get data then to plot 2d Gui.

But tons of error, any advice will be appreciated!

// This class is calleed by class

import java.io.*;

import java.util.List;

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.ListIterator;

import java.util.regex.*;

import java.util.StringTokenizer;

publicclass ParseFile

{

private String Filename="test.txt";

privateint x1, y1, x2, y2;// to plot lines from (x1,y1) to (x2,y2)

privateint xy[]=newint[206];

publicint[] setxy()

{

// parse a file to read line by line;

File file =new File(Filename);

try

{

BufferedReader br =new

BufferedReader(new FileReader(Filename));

String line;

String s1 ="0.5 setlinewidth 0.0 setgray";

String s2 ="stroke clear";

String s3 ="closepath fill";

String[] parts;

int iter = 0;

while ((line = br.readLine()) !=null )

{

iter++;

System.out.printf("iterative at %d\n",iter);

line = line.trim();

System.out.println(line);

while (line.equals(s1))//true

{

System.out.printf("Here String is %s \n",s1);

List<Integer> xList =new ArrayList<Integer>();

List<Integer> yList =new ArrayList<Integer>();

while ((line = br.readLine()) !=null && !line.equals(s2))

{

line = line.trim();

System.out.println(line);

parts = line.split("\\s+");

for (int j=0;j<parts.length-1;j++)

{

System.out.printf("parts is %s \n",parts[j]);

}

//System.out.printf("Here parts[1] is %s \n",parts[1]);

xList.add(Integer.parseInt(parts[0]));

yList.add(Integer.parseInt(parts[1]));

}

Integer[] x = xList.toArray(new Integer[xList.size()]);

Integer[] y = yList.toArray(new Integer[yList.size()]);

// Plotting here using x and y arrays

int m = xy.length/2-1;

System.out.println("Test in ParseFile.java");

for (int i = 0; i><m-1;i++)

{

xy[i]= x[i].intValue();

xy[i+m] = y[i].intValue();

System.out.printf("%d\n",xy[i]);

// to return these values to class LinesRectsCirclesJPanel

}

// return xy;

}

while (line.split("\\s+").length == 8)

{

List><Integer> xList =new ArrayList<Integer>();

List<Integer> yList =new ArrayList<Integer>();

String[] newpath = line.split("\\s+");

while ((line = br.readLine()) !=null && !line.equals(s2))

{

line = line.trim();

parts = line.split("\\s+");

xList.add(Integer.parseInt(parts[0]));

yList.add(Integer.parseInt(parts[1]));

}

Integer[] x = xList.toArray(new Integer[xList.size()]);

Integer[] y = yList.toArray(new Integer[yList.size()]);

// Plotting here using x and y arrays

int m = xy.length/2-1;

xy[0]= Integer.parseInt(newpath[5]);

xy[m+1] = Integer.parseInt(newpath[6]);

for (int i = 0; i<m-1;i++)

{

xy[i+1]= x[i].intValue();

xy[i+m+1] = y[i].intValue();

// to return these values to class LinesRectsCirclesJPanel

}

}

}

}

catch (Exception exception){

exception.printStackTrace();

}

return xy;

}

}

Here is the parsed txt file.

%!PS-Adobe-3.0 EPSF 3.0

%%BoundingBox: 0 0 612 792

%%Title: Developmental Testing

%%CreationDate: 06/07/2007 08:45:57

%%EndComments

/Helvetica findfont 9 scalefont setfont

0.5 setlinewidth 0.0 setgray

20.000020.0000 moveto

592.000020.0000 lineto /

592.0000 772.0000 lineto /

20.0000 772.0000 lineto /

20.000020.0000 lineto /

stroke clear

22.000022.0000 moveto

590.000022.0000 lineto /

590.0000 770.0000 lineto /

22.0000 770.0000 lineto /

22.000022.0000 lineto /

stroke clear

0.5000 1.0000 0.5000 setrgbcolor newpath 439.5350 127.3837 moveto

423.7250 100.0000 lineto /

423.7250 100.0000 lineto /

415.8200 100.0000 lineto /

415.8200 103.7287 lineto /

421.5722 103.7287 lineto /

435.2295 127.3837 lineto /

closepath fill

0.5 setlinewidth 0.0 setgray

439.5350 127.3837 moveto

423.7250 100.0000 lineto /

415.8200 100.0000 lineto /

415.8200 103.7287 lineto /

421.5722 103.7287 lineto /

435.2295 127.3837 lineto /

439.5350 127.3837 lineto /

stroke clear

0.5000 1.0000 0.5000 setrgbcolor newpath 534.3950 319.0698 moveto

542.3000 305.3779 lineto /

542.3000 305.3779 lineto /

534.3950 291.6861 lineto /

530.0895 291.6861 lineto /

537.9945 305.3779 lineto /

530.0895 319.0698 lineto /

closepath fill

0.5 setlinewidth 0.0 setgray

534.3950 319.0698 moveto

542.3000 305.3779 lineto /

534.3950 291.6861 lineto /

530.0895 291.6861 lineto /

537.9945 305.3779 lineto /

530.0895 319.0698 lineto /

534.3950 319.0698 lineto /

stroke clear

>

[8153 byte] By [ardmorea] at [2007-11-27 8:48:41]
# 1

here is the debugging message.

init:

deps-jar:

compile:

java.lang.NumberFormatException: For input string: "20.0000"

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

iterative at 1

%!PS-Adobe-3.0 EPSF 3.0

iterative at 2

at java.lang.Integer.parseInt(Integer.java:456)

at java.lang.Integer.parseInt(Integer.java:497)

at ParseFile.setxy(ParseFile.java:53)

at LinesRectsCirclesJPanel.paintComponent(LinesRectsCirclesJPanel.java:31)

at javax.swing.JComponent.paint(JComponent.java:1022)

at javax.swing.JComponent.paintChildren(JComponent.java:859)

at javax.swing.JComponent.paint(JComponent.java:1031)

at javax.swing.JComponent.paintChildren(JComponent.java:859)

at javax.swing.JComponent.paint(JComponent.java:1031)

at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)

at javax.swing.JComponent.paintChildren(JComponent.java:859)

%%BoundingBox: 0 0 612 792

iterative at 3

at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)

at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)

at javax.swing.RepaintManager.paint(RepaintManager.java:1128)

at javax.swing.JComponent.paint(JComponent.java:1008)

at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)

at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)

at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)

at java.awt.Container.paint(Container.java:1797)

%%Title: Developmental Testing

iterative at 4

%%CreationDate: 06/07/2007 08:45:57

iterative at 5

%%EndComments

iterative at 6

/Helvetica findfont 9 scalefont setfont

iterative at 7

0.5 setlinewidth 0.0 setgray

Here String is 0.5 setlinewidth 0.0 setgray

20.000020.0000 moveto

parts is 20.0000

parts is 20.0000

at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)

at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)

at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

ardmorea at 2007-7-12 20:56:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Integer.parseInt tries to parse an integer - the string "20.0000" is a real (double/float).Better to do something likeString numStr = "20.0000";numStr = numStr.substring(0,
RATiXa at 2007-7-12 20:56:18 > top of Java-index,Java Essentials,Java Programming...
# 3
Or he could use Double.parseDouble() and cast it to an int.
CaptainMorgan08a at 2007-7-12 20:56:18 > top of Java-index,Java Essentials,Java Programming...