Why do you throw the following error when clicking on the table of my jFrame?

1

Basically schedule a view in which I could enter data, modify, elminate, so that if I clicked on the table it would let me modify the data that I want, the problem is that it throws me an error that I do not understand and this does not let me move on.

I enclose the error:

  

Exception in thread "AWT-EventQueue-0"   java.lang.StringIndexOutOfBoundsException: String index out of range:   10 at java.lang.String.substring (String.java:1963) at   Sistema.Arriendobiblioteca.jTable1MouseClicked (Arriendobiblioteca.java:981)     at Sistema.Arriendobiblioteca.access $ 400 (Arriendobiblioteca.java:16)     at   Sistema.Arriendobiblioteca $ 5.mouseClicked (Arriendobiblioteca.java:177)     at   java.awt.AWTEventMulticaster.mouseClicked (AWTEventMulticaster.java:270)

I go to line 981 of my code that is according to the netbeans that is causing this problem.

I will attach that part of the code so that you can understand me:

private void tbuscarKeyReleased(java.awt.event.KeyEvent evt) {                                    
            String campo = this.tbuscar.getText();
    try {
        ConexionBD nuevos = new ConexionBD();
        Statement st = nuevos.conn.createStatement();

        String comando ="select count(*) from arriendo "
                + "inner join libros  on  arriendo.Libros_idLibros=libros.idLibros"
                + " where Libros_arriendo like '" + campo + "%'"
                + " or titulo_libro like '%" + campo + "%'"
                + " or Fecha_arriendo like '" + campo + "%'"
                + " or Fecha_devolucion like '%" + campo + "%'"
                + " or Fecha_entrega like '" + campo + "%'"
                + " or Costo_arriendo like '%" + campo + "%'"
                + " order by idArriendo asc";

        ResultSet rs = st.executeQuery(comando);
        this.jTable1.setModel(nuevos.consultaArriendo(campo));


    } catch (Exception e) {

    }
}                                   

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     
    int seleccion = jTable1.rowAtPoint(evt.getPoint());


    tcosto.setText(String.valueOf(jTable1.getValueAt(seleccion, 5)));
    nomArriendo.setText(String.valueOf(jTable1.getValueAt(seleccion, 0)));



    String fechaArridia, fechaArrimes, fechaArrian;
    String fechaEntdia, fechaEntmes, fechaEntan;
    String fechaDevdia, fechaDevmes, fechaDevan;


    fechaArrimes = String.valueOf(jTable1.getValueAt(seleccion, 1)).substring(3, 5);
    boxmes.setSelectedItem(fechaArrimes);

    fechaArridia = String.valueOf(jTable1.getValueAt(seleccion, 1)).substring(0, 2);
    boxdia.setSelectedItem(fechaArridia);

    fechaArrian = String.valueOf(jTable1.getValueAt(seleccion, 1)).substring(6, 10);
    boxan.setSelectedItem(fechaArrian);



    fechaEntmes = String.valueOf(jTable1.getValueAt(seleccion, 4)).substring(14, 16);
    boxenmes.setSelectedItem(fechaEntmes);
    fechaEntdia = String.valueOf(jTable1.getValueAt(seleccion, 4)).substring(11, 13);
    boxendia.setSelectedItem(fechaEntdia);
    fechaEntan = String.valueOf(jTable1.getValueAt(seleccion, 4)).substring(17, 21);
    boxenan.setSelectedItem(fechaEntan);


    fechaDevmes = String.valueOf(jTable1.getValueAt(seleccion, 6)).substring(25, 27);
    boxdevmes.setSelectedItem(fechaDevmes);
    fechaDevdia = String.valueOf(jTable1.getValueAt(seleccion, 6)).substring(22, 24);
    boxdevdia.setSelectedItem(fechaDevdia);
    fechaDevan = String.valueOf(jTable1.getValueAt(seleccion, 6)).substring(28, 32);
    boxdevan.setSelectedItem(fechaDevan);


    combolibro.setSelectedItem(String.valueOf(jTable1.getValueAt(seleccion, 3)));



    try {

        ConexionBD nuevos = new ConexionBD();
        Statement st = nuevos.conn.createStatement();

        String comando = "Select * from libros";
        ResultSet rs = st.executeQuery(comando);

        while (rs.next()) {


            combolibro.setSelectedItem(rs.getString("idLibros") + "   " + String.valueOf(jTable1.getValueAt(seleccion, 2)));
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }



    this.bcrear.setEnabled(false);
    this.bmodificar.setEnabled(true);
    this.beliminar.setEnabled(true);           // TODO add your handling code here:
}                                    

The "box ..." that is the name that the buttons of my views receive, I have 3 different dates with different names.

    
asked by sebastian ortiz 19.07.2018 в 11:17
source

2 answers

0

Your problem is here

fechaArrian = String.valueOf(jTable1.getValueAt(seleccion, 1)).substring(6, 10);

You are doing a substring from position 6 to position 10 (not inclusive) of a String that is at most 9 in length.

    
answered by 19.07.2018 в 11:21
0

The error is in:

  

String index out of range: 10

Probably the data from where you want to do the substring does not have that length, therefore not having said pointer inside the memory marks an error.

    
answered by 19.07.2018 в 15:36