Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/03/2015, 11:31
Avatar de maiksix
maiksix
 
Fecha de Ingreso: noviembre-2014
Ubicación: Sabadell
Mensajes: 124
Antigüedad: 9 años, 5 meses
Puntos: 1
Number format exception

Hola!

Estoy haciendo un algoritmo y estoy empezando en la lectura de ficheros, al leer un fichero me sale el siguiente error:

"Exception in thread "main" java.lang.NumberFormatException: For input string: "2,0"
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1222)
at java.lang.Float.parseFloat(Float.java:422)
at InputsReader.muestraContenido(InputsReader.java:42 )
at Starter.main(Starter.java:10)"

He estado leyendo y se a que se debe, pero no como solucionarlo. He leído que quitando espacios al fichero se solucionaría pero no lo hace (ya me lo suponía)

El código es

Código:
public class InputsReader {
	
	public static void muestraContenido(String archivo) throws FileNotFoundException, IOException {
	      String cadena;
	      Input inputs = null;
	      int nNodes = 0;
	      FileReader f = new FileReader(archivo);
	      BufferedReader b = new BufferedReader(f);
	      
	   // 1. COUNT THE # OF NODES (# OF LINES IN nodesFilePath)
	      while((cadena = b.readLine())!=null) {
	    		  nNodes++;
	          System.out.println(cadena + "Numero de nodos:");
	      }
	      b.close();
	   // 2. CREATE THE INPUTS OBJECT WITH nNodes
          inputs = new Input(nNodes);
          
       // 3. CREATE ALL NODES AND FILL THE NODES LIST
          FileReader reader = new FileReader(archivo);
          Scanner in = new Scanner(reader);
          
          String s ="2.8";
          int k = 0;
          
          while( in.hasNextLine() )
          {   
        	  
        	  s = in.next();

                 float x = Float.parseFloat(s); AQUÍ ESTÁ EL FALLO

                  float y = in.nextFloat();
                  Node node = new Node(k, x, y);
                  inputs.getNodes()[k] = node;
                  k++;
                  System.out.println("Coordenada x:" + x + "Coordenadad y:" + y);
              }
          }
	
	}
He marcado en rojo el error ya que se donde está pero no se como solucionarlo. A ver si alguien puede echarme un mano

Gracias y un saludo!
__________________
Going hard for too long... Can't get enough