Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/01/2013, 16:11
_Ruben_
 
Fecha de Ingreso: enero-2008
Mensajes: 201
Antigüedad: 16 años, 3 meses
Puntos: 39
Respuesta: Bucle infinito do/while desesperación TOTAL

La verdad es que no se muy bien porque no te funciona, yo para leer un entero siempre lo hago de esta forma:
Código:
linea = teclado.nextLine();
respuesta = Integer.parseInt(linea);
por lo que el código del método main quedaría así:
Código:
	public static void main(String[] args) throws IOException {
		
		String linea = "";
		int respuesta = 0;

		Scanner teclado = new Scanner(System.in);

		// PARA EL MENU USAR DO WHILE

		do {
			menu();
			try {
				linea = teclado.nextLine();
				respuesta = Integer.parseInt(linea);
			} catch (NumberFormatException e) {
				respuesta = 0;
				System.out.println("Ha ocurrido un error. Por favor, introduzca un número válido.");
				System.err.println(e);
			}
			switch (respuesta) {
			case 1:
				numcomp();
				break;
			case 2:
				jornada();
				break;
			case 3:
				imprimir();
				break;
			case 4:
				leer();
				break;
			case 5:
				System.out.println("Saliendo del menú principal...");
				break;
			default:
				System.out.println("No existe una opción " + linea
						+ ". Por favor, introduzca un número válido.");
				break;
			}
		} while (respuesta != 5);
		// TODO Auto-generated method stub

	}