Exception in thread "main" java.lang.NullPointerException-CRUD Java MySQL

I'm trying to make a CRUD, when I come across this error and don't know how to solve.

Error:

Exception in thread "main" java.lang.NullPointerException at view.Productview.(Productview.java:29) at main.Run.main (Run.java: 8)

Is a jFrame, code below:

package view;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTable;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.border.LineBorder;

import dao.ProdutoDAO;
import table.ProdutoTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.BevelBorder;

public class ProdutoView extends javax.swing.JFrame {
    private JTextField tfCodigo;
    private JTextField tfDescricao;
    private JTextField tfPreco;
    private JTextField tfPesquisarDescricao;    
    private JTable tbProduto;

public ProdutoView() {
    setResizable(false);
    setTitle("Produto");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);      
    setBounds(650, 400, 450, 375);
    getContentPane().setLayout(null);
    tbProduto.setModel(new ProdutoTableModel(new ProdutoDAO().listarTodos()));

    JLabel lblNewLabel = new JLabel("C\u00F3digo:");
    lblNewLabel.setBounds(58, 50, 46, 14);
    getContentPane().add(lblNewLabel);

    JLabel lblNewLabel_1 = new JLabel("Descri\u00E7\u00E3o:");
    lblNewLabel_1.setBounds(58, 75, 63, 14);
    getContentPane().add(lblNewLabel_1);

    JLabel lblNewLabel_2 = new JLabel("Pre\u00E7o:");
    lblNewLabel_2.setBounds(58, 100, 46, 14);
    getContentPane().add(lblNewLabel_2);

    tfCodigo = new JTextField();
    tfCodigo.setBounds(147, 47, 198, 20);
    getContentPane().add(tfCodigo);
    tfCodigo.setColumns(10);

    tfDescricao = new JTextField();
    tfDescricao.setBounds(147, 72, 198, 20);
    getContentPane().add(tfDescricao);
    tfDescricao.setColumns(10);

    tfPreco = new JTextField();
    tfPreco.setBounds(147, 97, 198, 20);
    getContentPane().add(tfPreco);
    tfPreco.setColumns(10);

    JButton btLimpar = new JButton("Limpar");
    btLimpar.setBounds(58, 135, 89, 23);
    getContentPane().add(btLimpar);

    JButton btExcluir = new JButton("Excluir");
    btExcluir.setBounds(157, 135, 89, 23);
    getContentPane().add(btExcluir);

    JButton btSalvar = new JButton("Salvar");
    btSalvar.setBounds(256, 135, 89, 23);
    getContentPane().add(btSalvar);

    JLabel lblNewLabel_3 = new JLabel("Pesquisar (Descri\u00E7\u00E3o):");
    lblNewLabel_3.setBounds(58, 258, 188, 14);
    getContentPane().add(lblNewLabel_3);

    tfPesquisarDescricao = new JTextField();
    tfPesquisarDescricao.setBounds(58, 279, 322, 20);
    getContentPane().add(tfPesquisarDescricao);
    tfPesquisarDescricao.setColumns(10);

    tbProduto = new JTable();
    tbProduto.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    tbProduto.setBounds(60, 237, 320, -54);
    getContentPane().add(tbProduto);




    }
}

package main;

import view.ProdutoView;

public class Run {

    public static void main(String[] args) {
        new ProdutoView().setVisible(true);
    }
}

The project as a whole

Window

 0
Author: RXSD, 2019-04-17

1 answers

This little face is not instantiated or null.

tbProduto.setModel(new ProdutoTableModel(new ProdutoDAO().listarTodos()));

Instantiate-which will work.! I hope I helped.

 2
Author: Filipe L. Constante, 2019-04-17 18:43:46