Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/09/2016, 02:36
finalgamestudio
 
Fecha de Ingreso: julio-2014
Mensajes: 5
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: NullPointException al devolver una array

Perdon, pondre el codigo entero:

Clase principal

Código:
public class V_frame extends java.awt.Frame {

    public bdtickets bdtickets;
    public DefaultTableModel tablaTickets;
    public accionTickets tabti;
    public ResultSet a =null;
    
    public V_frame() throws SQLException {
        initComponents();
        
        tabti = new accionTickets(this);
        
        
        JFrame fprincipal = new JFrame("FACTURACIÓ VERDULERIA");
        fprincipal.setLocationRelativeTo(null);
        fprincipal.setLayout(new BorderLayout());
        setExtendedState(fprincipal.MAXIMIZED_BOTH);
        

        tabti.cargarTickets();
        try {
            tabti.llenarTickets(); //ESTE ES EL METODO QUE LLAMO PARA CARGAR DATOS
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(V_frame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(V_frame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(V_frame.class.getName()).log(Level.SEVERE, null, ex);
        }

        fprincipal.pack();
SEGUNDA CLASE:

Código:
public class accionTickets {
    
public DefaultTableModel tablaTickets;
public V_frame principal;
public bdtickets bdt;
public Vector tickets;
public ResultSet resultado;
//private ResultSet resultado;
    public accionTickets(V_frame principal)
    {
        bdt = new bdtickets();
        this.principal=principal;
    }
    
    public void cargarTickets()
    {
        tablaTickets = new DefaultTableModel(new String[]{"ID","FECHA","IMPORTE"},0);
        principal.getTblTickets().setModel(tablaTickets);

    }
    public void llenarTickets() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
    {
        ResultSet resultado;
        System.out.print("PRIMERO");
        bdt = new bdtickets();

        resultado = bdt.consultarTickets();//AQUI LLAMO AL METODO PARA HACER LA CONSULTA A LA BD
        while (resultado.next())
        {
            System.out.print(resultado.getString("ID")+"holaaaa");
            tickets = new Vector();
            tickets.addElement(resultado.getString("ID"));
            tickets.addElement(resultado.getString("FECHA"));
            tickets.addElement(resultado.getString("IMPORTE"));
            tablaTickets.addRow(tickets);
            System.out.print(resultado.getString("ID"));
        }
        
        
    }
    
}

3A CLASE, DONDE HAY LA CONSULTA A LA BD:

Código:
public class bdtickets {
 
    private bdprincipal conectar;
    private Statement statment;
    public ArrayList lista;
    public ResultSet array;
    
    public bdtickets()
    {
        conectar = new bdprincipal();
    }
    public ResultSet consultarTickets() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
    {
        conectar.Connection();
        String consulta = "SELECT * FROM TICKETSDIARIOS ORDER BY ID";    
        array = statment.executeQuery(consulta);
        return array; 
       
    }
    
}