Erro de execução da AbstractTableModel

1 resposta
jsnpereira

Pessoal,

Eu estou tentando para implementar um jcheckbox na tabela mas deu erro de executar, veja o mensagem de erro em baixo.

GetValueAT colunas: 0 - Linhas0 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.JTable.prepareRenderer(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source) at javax.swing.plaf.ComponentUI.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.JViewport.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.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.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source) at javax.swing.RepaintManager$PaintManager.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 java.awt.Window.paint(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.access$700(Unknown Source) at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.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)
O código que criei
import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
public class ModeloConceitos extends AbstractTableModel {
	private String[] colunaNames = { "Marcar", "ID", "Nome" };
	private ArrayList<AlunosConceitos> al;
	@SuppressWarnings("rawtypes")
	private Class[] tipoClass = { boolean.class, Integer.class, String.class };

	public ModeloConceitos(ArrayList<AlunosConceitos> al) {
		this.al = al;
	}

	@Override
	public int getColumnCount() {
		return colunaNames.length;
	}

	@Override
	public int getRowCount() {
		return al.size();
	}

	public String getColumnName(int col) {
		return colunaNames[col];
	}

	@SuppressWarnings("unchecked")
	public Class getColumnClass(int col) {
		return tipoClass[col];
	}

	@Override
	public Object getValueAt(int row, int col) {
		System.out.println("GetValueAT colunas: " + col + " - Linhas" + row);
		switch (col) {
		case 0:
			new Boolean(false);
		case 1:
			return al.get(row).getIdAlunos();
		case 2:
			return al.get(row).getNomeAluno();
		default:
			return null;
		}

	}

}
Espero que vocês me ajuda ou dar uma dicas. Obrigado!!!

1 Resposta

Margel_Douglas

Parece td certo ai cara …

Da uma conferida ali no teu getValueAt se não esta dando nullPointer, ou se a tua lista não é nula

public Object getValueAt(int row, int col) {  
        Aluno a = al.get(row);
        System.out.println( "Nulo: "+a==null );
Criado 23 de novembro de 2012
Ultima resposta 24 de nov. de 2012
Respostas 1
Participantes 2