"AWT-EventQueue-0" java.lang.NullPointerException

0

I am generating this code:

public void llenarTabla(){
    this.modelSalon = new DefaultTableModel(){
    public boolean isCellEditable(int row, int colum){
    return false;
    }
    };
    this.modelSalon.setColumnCount(0);
    this.modelSalon.addColumn("Num_Salon");
    this.modelSalon.addColumn("Cant_Camas");
    this.modelSalon.addColumn("area");
    this.modelSalon.addColumn("cedula_doctor");
    List<Salones> lista = this.salBo.consultaTodos();
    this.modelSalon.setNumRows(lista.size());
        for (int i = 0; i < lista.size(); i++) {
            Salones sal = lista.get(i);
            this.modelSalon.setValueAt(sal.getNum_salon(), i, 0);
            this.modelSalon.setValueAt(sal.getCant_camas(), i, 1);
            this.modelSalon.setValueAt(sal.getArea(), i, 2);
            Doctor doc = this.docBo.consultaXCedula(sal.getCedula_doctor());
            this.modelSalon.setValueAt(doc.getCedula(), i, 3);
        }
        this.TableSalon.setModel(modelSalon);

    }

But you send me the following error:

  

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException     at windows.ManteSalon.llenarTabla (ManteSalon.java:81) at   Windows.ManteSalon. (ManteSalon.java:59) at   Windows.ManteSalon $ 7.run (ManteSalon.java:449) at   java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:311) at   java.awt.EventQueue.dispatchEventImpl (EventQueue.java:756) at   java.awt.EventQueue.access $ 500 (EventQueue.java:97) at   java.awt.EventQueue $ 3.run (EventQueue.java:709) at   java.awt.EventQueue $ 3.run (EventQueue.java:703) at   java.security.AccessController.doPrivileged (Native Method) at   java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege (ProtectionDomain.java:80)     at java.awt.EventQueue.dispatchEvent (EventQueue.java:726) at   java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:201)     at   java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:116)     at   java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:105)     at   java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:101)     at   java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:93)     at java.awt.EventDispatchThread.run (EventDispatchThread.java:82)   BUILD STOPPED (total time: 16 minutes 46 seconds)

I have reviewed it, I have cleaned the program and others but the problem persists! within the sql if there is information within those fields. They could guide me. Thanks

    
asked by Felix mejias 02.12.2017 в 02:49
source

1 answer

0

I think the detail is that you create the model of the table, then you create the columns but you do not add it to the table but after trying to add the data so by that time the structure of the table does not exist yet. It's null.

  

this.TableSalon.setModel (modelSalon);

place it after:

  

this.modelSalon.addColumn ("cedula_doctor");

    
answered by 02.12.2017 в 03:27