Ajuda para localizar esse java.lang.NullPointerException

3 respostas
E

Galera peço ajuda, pois nao consegui localizar esse erro java.lang.NullPointerException

Segue o erro:

Exception occurred during event dispatching:
java.lang.NullPointerException
	at javax.swing.plaf.metal.MetalButtonUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JLayeredPane.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
	at java.awt.Container.paint(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(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.pumpEventsForFilter(Unknown Source)
	at java.awt.Dialog$1.run(Unknown Source)
	at java.awt.Dialog$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.Dialog.show(Unknown Source)
	at java.awt.Component.show(Unknown Source)
	at java.awt.Component.setVisible(Unknown Source)
	at java.awt.Window.setVisible(Unknown Source)
	at java.awt.Dialog.setVisible(Unknown Source)
	at views.MenuOpcoes$7.actionPerformed(MenuOpcoes.java:275)
	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.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)

Chamada no menu

jMenuDevolucao.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JanelaDevolucao dev = new JanelaDevolucao(f);
				dev.setModal(true);
				dev.setVisible(true);
			}
		});

Essa é a tela

package views;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import Beans.locacao_locadora;

import com.swtdesigner.SwingResourceManager;

@SuppressWarnings("serial")
public class JanelaDevolucao extends JDialog {

	private JTable tabela;
	private JScrollPane scrollPane_1;
	private JTextField codigo_filme;
	JButton consultar;
	JFormattedTextField data;

	private static EntityManagerFactory f = null;

	public JanelaDevolucao(EntityManagerFactory f1) {

		this.setTitle("DEVOLUÇÃO");
		getContentPane().setForeground(new Color(30, 144, 255));
		getContentPane().setLayout(null);
		Container tela = getContentPane();
		setLayout(null);

		f = f1;

		tela.setBackground(new Color(181, 181, 181));
		consultar = new JButton("Consultar");
		consultar.setBounds(0, 0, 0, 0);
		tela.add(consultar);

		//	   	 DESABILITAM-SE ALGUNS BOTÕES 
		consultar.setEnabled(true);

		setSize(733, 407);

		setLocationRelativeTo(null);// CENTRALIZA A JANELA 

		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.BOLD, 12));
		label.setText("Pesquisa Locação");
		label.setBounds(35, 0, 105, 14);
		getContentPane().add(label);

		final JSeparator separator = new JSeparator();
		separator.setBounds(145, 6, 565, 8);
		getContentPane().add(separator);

		final JSeparator separator_1 = new JSeparator();
		separator_1.setOrientation(SwingConstants.VERTICAL);
		separator_1.setBounds(10, 10, 11, 66);
		getContentPane().add(separator_1);

		final JSeparator separator_1_1 = new JSeparator();
		separator_1_1.setOrientation(SwingConstants.VERTICAL);
		separator_1_1.setBounds(709, 6, 11, 76);
		getContentPane().add(separator_1_1);

		final JSeparator separator_2 = new JSeparator();
		separator_2.setBounds(10, 6, 19, 14);
		getContentPane().add(separator_2);

		final JLabel label_1 = new JLabel();
		label_1.setText("Código do filme");
		label_1.setBounds(22, 36, 73, 14);
		getContentPane().add(label_1);

		final JButton emAbertoButton = new JButton();
		emAbertoButton.setModel(null);
		emAbertoButton.setIcon(SwingResourceManager.getIcon(JanelaDevolucao.class, "/picture/search_magnifier_32.jpg.png"));
		emAbertoButton.setText("Em aberto");
		emAbertoButton.setBounds(565, 32, 117, 23);
		getContentPane().add(emAbertoButton);

		final JSeparator separator_3 = new JSeparator();
		separator_3.setBounds(10, 78, 700, 20);
		getContentPane().add(separator_3);

		final JLabel label_2 = new JLabel();
		label_2.setFont(new Font("Dialog", Font.BOLD, 12));
		label_2.setText("Pesquisa Locação");
		label_2.setBounds(25, 0, 105, 14);
		separator_3.add(label_2);

		final JSeparator separator_2_1 = new JSeparator();
		separator_2_1.setBounds(0, 1, 19, 14);
		separator_3.add(separator_2_1);

		final JSeparator separator_2_2 = new JSeparator();
		separator_2_2.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_2);

		final JSeparator separator_4 = new JSeparator();
		separator_4.setBounds(111, 10, 565, 8);
		separator_3.add(separator_4);

		final JSeparator separator_5 = new JSeparator();
		separator_5.setBounds(109, 10, 591, 8);
		separator_3.add(separator_5);

		final JSeparator separator_2_3 = new JSeparator();
		separator_2_3.setBounds(0, 0, 19, 14);
		separator_3.add(separator_2_3);

		final JSeparator separator_2_4 = new JSeparator();
		separator_2_4.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_4);

		final JSeparator separator_6 = new JSeparator();
		separator_6.setBounds(113, 10, 565, 8);
		separator_3.add(separator_6);

		final JSeparator separator_7 = new JSeparator();
		separator_7.setBounds(115, 10, 585, 8);
		separator_3.add(separator_7);

		final JSeparator separator_2_5 = new JSeparator();
		separator_2_5.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_5);

		final JSeparator separator_8 = new JSeparator();
		separator_8.setBounds(113, 10, 587, 8);
		separator_3.add(separator_8);

		final JSeparator separator_2_6 = new JSeparator();
		separator_2_6.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_6);

		final JSeparator separator_9 = new JSeparator();
		separator_9.setBounds(115, 10, 585, 8);
		separator_3.add(separator_9);

		final JSeparator separator_2_7 = new JSeparator();
		separator_2_7.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_7);

		final JSeparator separator_10 = new JSeparator();
		separator_10.setBounds(113, 10, 587, 8);
		separator_3.add(separator_10);

		final JSeparator separator_2_8 = new JSeparator();
		separator_2_8.setBounds(0, 10, 19, 14);
		separator_3.add(separator_2_8);

		codigo_filme = new JTextField();
		codigo_filme.setBounds(114, 33, 88, 20);
		getContentPane().add(codigo_filme);

		final JLabel label_3 = new JLabel();
		label_3.setFont(new Font("Dialog", Font.BOLD, 12));
		label_3.setText("Dados locação");
		label_3.setBounds(35, 84, 105, 14);
		getContentPane().add(label_3);

		final JSeparator separator_1_2 = new JSeparator();
		separator_1_2.setOrientation(SwingConstants.VERTICAL);
		separator_1_2.setBounds(10, 93, 11, 66);
		getContentPane().add(separator_1_2);

		final JSeparator separator_3_1 = new JSeparator();
		separator_3_1.setBounds(10, 157, 700, 20);
		getContentPane().add(separator_3_1);

		final JSeparator separator_1_1_1 = new JSeparator();
		separator_1_1_1.setOrientation(SwingConstants.VERTICAL);
		separator_1_1_1.setBounds(709, 88, 11, 71);
		getContentPane().add(separator_1_1_1);

		final JLabel label_4 = new JLabel();
		label_4.setText("Cód. locação");
		label_4.setBounds(23, 111, 88, 14);
		getContentPane().add(label_4);

		final JLabel cod_locacao = new JLabel();
		cod_locacao.setBounds(102, 111, 54, 14);
		getContentPane().add(cod_locacao);

		final JLabel clienteLabel = new JLabel();
		clienteLabel.setText("Cliente");
		clienteLabel.setBounds(51, 131, 54, 14);
		getContentPane().add(clienteLabel);

		final JLabel label_5 = new JLabel();
		label_5.setBounds(102, 131, 100, 14);
		getContentPane().add(label_5);

		final JLabel dependenteLabel = new JLabel();
		dependenteLabel.setText("Dependente");
		dependenteLabel.setBounds(243, 111, 59, 14);
		getContentPane().add(dependenteLabel);

		final JLabel label_6 = new JLabel();
		label_6.setBounds(308, 111, 88, 14);
		getContentPane().add(label_6);

		final JLabel label_7 = new JLabel();
		label_7.setText("Data Locação");
		label_7.setBounds(240, 131, 73, 14);
		getContentPane().add(label_7);

		final JLabel label_8 = new JLabel();
		label_8.setBounds(308, 131, 88, 14);
		getContentPane().add(label_8);

		final JLabel operadorLabel = new JLabel();
		operadorLabel.setText("Operador");
		operadorLabel.setBounds(469, 111, 54, 14);
		getContentPane().add(operadorLabel);

		final JLabel label_9 = new JLabel();
		label_9.setBounds(529, 111, 88, 14);
		getContentPane().add(label_9);

		final JButton devolverButton = new JButton();
		devolverButton.setText("Devolver");
		devolverButton.setBounds(10, 172, 93, 23);
		getContentPane().add(devolverButton);

		final JButton devolverTodasButton = new JButton();
		devolverTodasButton.setText("Devolver Todas");
		devolverTodasButton.setBounds(133, 172, 117, 23);
		getContentPane().add(devolverTodasButton);

		scrollPane_1 = new JScrollPane();
		scrollPane_1.setBackground(Color.WHITE);
		scrollPane_1.setBounds(123, 213, 427, 105);
		getContentPane().add(scrollPane_1);

		tabela = new JTable();
		scrollPane_1.setViewportView(tabela);
		scrollPane_1.setViewportView(tabela);

		final JButton concluirButton = new JButton();
		concluirButton.setIcon(SwingResourceManager.getIcon(JanelaDevolucao.class, "/picture/OKShield-32.png"));
		concluirButton.setText("Concluir");
		concluirButton.setBounds(487, 343, 117, 23);
		getContentPane().add(concluirButton);

		final JButton sairButton = new JButton();
		sairButton.setIcon(SwingResourceManager.getIcon(JanelaDevolucao.class, "/picture/porta.png"));
		sairButton.setText("Sair");
		sairButton.setBounds(633, 343, 87, 23);
		getContentPane().add(sairButton);

		//	 Ações Botões

		codigo_filme.addFocusListener(new FocusListener() {
			public void focusLost(FocusEvent arg0) {

				if (!codigo_filme.getText().trim().equals("")) {

					EntityManager me = f.createEntityManager();

					locacao_locadora loc = new locacao_locadora();
					
					int cod_filme=0;

					cod_filme = Integer.parseInt(codigo_filme.getText());

					//
					// <<<<<< Localizando o Registro no Banco = FIND >>>>>
					//
					StringBuilder jpql = new StringBuilder("SELECT p FROM locacacao_locadora p WHERE p.cod_filme= " + cod_filme);

					if (jpql != null) {
						cod_locacao.setText(String.valueOf(loc.getCod_loc()));
					}

					else {
						JOptionPane.showMessageDialog(null, "Filme não locado!");

					}

				}
			}

			public void focusGained(FocusEvent arg0) {
				// TODO Auto-generated method stub

			}

		});
	}

	public static void main(String args[]) {

		JanelaDevolucao app = new JanelaDevolucao(f);

		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

}

[b]Desde já agradeço a ajuda

3 Respostas

_kitty

bom, o q eu posso te disser é q ele tentou acessar algo q estava nulo ou que não existe, como uma posição extra num vetor, ou um caminho incorreto. Verifique se vc inicializou tudo, se vc separou lugar na memoria pra os objetos, pq senao ele tenta acessar algo q ainda naum foi inicializado.

se cuida
:wink:

vi-gb

Na linha 37 do erro esta isso views.MenuOpcoes$7.actionPerformed(MenuOpcoes.java:275)
Voce tem uma classe MenuOpcoes? Acho que pode ser nela no actionPerformed o erro, tvz linha 275, nao entendo tao bem de erros mas acho que pode ser.

Considerando a chamada do menu que voce passou, f deve estar null, e na linha 273 do seu codigo voce tenta acessar um metodo dele, creio que isso da erro de null

M

vi-gb:
Na linha 37 do erro esta isso views.MenuOpcoes$7.actionPerformed(MenuOpcoes.java:275)
Voce tem uma classe MenuOpcoes? Acho que pode ser nela no actionPerformed o erro, tvz linha 275, nao entendo tao bem de erros mas acho que pode ser.

Isso mesmo. O problema está na classe views.MenuOpcoes, dentro do método actionPerformed, na linha 275.

Tem certeza que o código está do jeito que você postou? Parece que quando a chamada a seguir é feita:

dev.setVisible(true);

A variável ‘dev’ é null. Por isso acontece um NullPointerException.

Criado 6 de dezembro de 2009
Ultima resposta 7 de dez. de 2009
Respostas 3
Participantes 4