ArrayIndexOutOfBoundsException when selecting input value [closed]

1

In my program, when you enter the query menu, the user is asked for a series of data. When you reach the section where you enter the month of your birth this menu does not appear, the program is closed and the following exception appears:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
    at CapturasDatos.main(CapturasDatos.java:63)

The section of the code that produces the error is the following:

String[] Mes = {"Enero","Febrero","Marzo","Abril","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"};
mes_opcion = (String)JOptionPane.showInputDialog(null,"Selecciona","MES DE NACIMIENTO",JOptionPane.QUESTION_MESSAGE,null,Mes,Mes[11]);

Why is the error?

    
asked by Stephanie B Bautista 16.02.2017 в 05:28
source

1 answer

8

Where you define

String[] Mes = {"Enero","Febrero","Marzo","Abril","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"};

You have all the months, except "Mayo". This means that this arrangement has only 11 elements (numbered from 0 to 10, that is, from Mes[0] to Mes[10] ).

When trying to call Mes[11] , the exception is thrown since there is no such position in the array.

    
answered by 16.02.2017 в 06:02