Así por encima y sin perder mucho tiempo, tienes una variable que se llama bandeja que no la estás inicializando.
Guenas.
Si te fijas tu codigo es circular, por eso te dara un StackOverflow si inicializas la variable bandeja en BDDUser.
Lo que debes hacer es desde bandeja pasarle this a BDDUser o a la inversa, segun te convenga.
Salut,
Paposo
Hola a todos, estoy teniendo un problema en un proyecto de una plataforma de envio de mails. Ya se que el error es un nullpointerexception pero por mas que instancie de otra manera el objeto BandejaDeEntrada, me tira un stackOverFlowError y no se como solucionarlo
El log es el siguiente:
[code]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Bdd.BDDUser.rellenarTabla(BDDUser.java:67)
at Plataforma.BandejaDeEntrada.(BandejaDeEntrada.java:53)
at Plataforma.IniciarSesion$1.actionPerformed(IniciarSesion.java:57)
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.plaf.basic.BasicButtonListener.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)
[/code]
El codigo perteneciente al proyecto es
BDDUser
[code]
package Bdd;
import java.sql.*;
import javax.swing.JOptionPane;
import Plataforma.BandejaDeEntrada;
public class BDDUser {
ConexionBDD cn;
Plataforma.BandejaDeEntrada bandeja=null;
public int size;
public ResultSetMetaData rm;
public BDDUser() {
cn = new ConexionBDD();
}
public void rellenarTabla(){
try{
PreparedStatement pstm = cn.getConnection().prepareStatement("SELECT * from mensajes");
ResultSet res = pstm.executeQuery();
while(res.next()){
Object[] fila=new Object[3];
fila[0]=res.getString("emisor");
fila[1]=res.getString("asunto");
fila[2]=res.getString("mensaje");
bandeja.getModelo().addRow(fila);
}
bandeja.getTable().updateUI();
res.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}[/code]
Bandeja De Entrada
[code]
package Plataforma;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import Bdd.BDDUser;
import java.awt.BorderLayout;
import java.awt.ScrollPane;
public class BandejaDeEntrada extends JFrame {
private static final long serialVersionUID = 1L;
//IniciarSesion iniciar = new IniciarSesion();
private JTable table;
private DefaultTableModel modelo;
public BandejaDeEntrada() {
setTitle("Bandeja De Entrada");
setSize(703, 367);
getContentPane().setLayout(null);
JButton btnActualizar = new JButton("Actualizar");
btnActualizar.setBounds(595, 11, 89, 23);
getContentPane().add(btnActualizar);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] { "Enviados", "Recibidos" }));
comboBox.setToolTipText("Enviados\r\nRecibidos");
comboBox.setBounds(462, 12, 123, 20);
getContentPane().add(comboBox);
JButton btnRedactar = new JButton("Redactar");
btnRedactar.setBounds(10, 11, 89, 23);
getContentPane().add(btnRedactar);
table = new JTable();
table.setBounds(10, 45, 667, 273);
getContentPane().add(table);
modelo=new DefaultTableModel(){
@Override
public boolean isCellEditable(int fila,int columna){
return false;
}
};
table=new JTable(modelo);
modelo.addColumn("De:");
modelo.addColumn("Asunto");
modelo.addColumn("Mensaje:");
BDDUser user=new BDDUser();
user.rellenarTabla();
}[/code]