Table Not Loading

Asked

Viewed 51 times

2

I’m trying to make the table list load and not loading always gives this error

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
The constructor PanelListClientes() is undefined

at view.FramePrincipal.listClientClicked(FramePrincipal.java:118)
at view.FramePrincipal$6.actionPerformed(FramePrincipal.java:94)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

My view code is this

public class PanelListClientes extends JPanel {
private JTable table;

/**
 * Create the panel.
 */

public PanelListClientes(TableCliente tablecliente) {
    setLayout(null);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(10, 181, 430, 108);
    add(scrollPane);

    table = new JTable();
    table.setModel(tablecliente);
    scrollPane.setViewportView(table);

    JButton btnCarregarTabela = new JButton("Carregar Tabela");
    btnCarregarTabela.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CarregarClicked(e);
        }
    });
    btnCarregarTabela.setBounds(267, 135, 142, 23);
    add(btnCarregarTabela);

}

protected void CarregarClicked(ActionEvent e) {
    ControleCliente cCliente = new ControleCliente();
    cCliente.constroiTabela();

}

The error method is the one from the main menu

protected void listClientClicked(ActionEvent e) {
    PanelListClientes plClientes = new PanelListClientes();
    this.setContentPane(plClientes);

}

É um menu JFrame chamando a JPanel para depois carregar a tabela

1 answer

2


The error is very clear. On this line:

PanelListClientes plClientes = new PanelListClientes();

you are trying to start the class with a constructor without parameters, but in your class PanelListClientes there’s a builder waiting for a guy TableCliente as a parameter.

In java, when you don’t write a constructor for a class, you create a default constructor with no parameters that you don’t see, but it’s there when the class is instantiated. From the moment you define a constructor, whether with parameters or not, the compiler understands that you are taking responsibility for initializing the class and creates nothing.

To solve, you must respect the constructor you created yourself, and pass the expected parameter, or create an alternative initialization of your class with a constructor without parameter.

  • Oh yes I understood, perfect more .

  • @Diegocruz, I think there’s been a mistake in your understanding of your own code. If you want to start without passing the table, so created constructor getting a?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.