Java - Ayuda paso por referencia

   
Vista:

Ayuda paso por referencia

Publicado por geronimo (20 intervenciones) el 14/11/2010 23:38:58
hola gente, tengo un problema con el paso por referencia en java!
el tema es asi!

tengo un JDialog donde:

public class JDialog implements JActionListener{
JTextField edit1, edit2,.....
JLabel label1,label2,.....
JButtom boton!

Vector<Persona> lista ; //ACA EL TEMA

public JDialog (Vector<Persona> lista){

boton = new JButtom("aceptar");
boton.addActionListener(this);
//agrego botones y labels y demas

/*el tema es que quiero que cuando clieckee en el boton el evento cree una persona y la agregue a esta lista que pase como paramentro ... lo que hago es esto*/

this.lista = lista; // ACA LA PIFIADA

}

/* este es mi actionperformed*/
public void actionPerformed(ActionEvent arg0) {


Persona p = new Persona();
p.setApellido(eApellido.getText());
p.setNombre(eNombre.getText());
p.setEdad(Integer.parseInt(eEdad.getText()));
p.setDireccion(eDireccion.getText());
this.lista.add(p); // o lista.add(p) /*AERROR ERROR*/


this.dispose();
}


}


Es como que no puedo copiar una referencia que llego en el metodo....no entiendo, es un tema teorico parece...pero no entiendo bien cono funciona esto de pasar copias de referencias!

Digo q el error esta ahi porq si creo persona en el constructor y le pongo valores...se hace bien!
el tema es q quiero poder leerlos de los edit y para eso tiene q ser cuando apriete el boton

SIN MAS

LA EXCEPTION:

Exception occurred during event dispatching:
java.lang.NullPointerException
at VentanaSecundaria.actionPerformed(VentanaSecundaria.java:74)
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.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 VentanaSecundaria.<init>(VentanaSecundaria.java:58)
at VentanaPrincipal.actionPerformed(VentanaPrincipal.java:46)
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.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)


ESPERO QUE ME SEPAN EXPLICAR PORQUE PASA ESTO, MAS QUE DARME LA SOLUCION

un saludo ...
y gracias desde ya
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder