Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/08/2008, 04:32
marilia15
 
Fecha de Ingreso: agosto-2008
Mensajes: 19
Antigüedad: 15 años, 8 meses
Puntos: 0
llamada a metodo de otra clase

Hola, soy novata con java, y tengo un error al hacer una llamada a unmetodo de otra clase.


Es un ejercicio muy sencillo, una clase de tipo JFRAME tiene unbotón que hace una llamada al metodo HOLA de otra clase de tipo JPANEL (este panel no esta incluido en el jframe).

Estas son mis dos clases java:

---------------------------------------------
import javax.swing.JPanel;
public class panel extends JPanel {
public void hola(){
System.out.println("hola");
}
}
----------------------------------------------

Y esta es la clase que hace la llamada a la clase anterior:
------------------------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

public class ventana extends JFrame {
public panel the_panel;
public static void main(String args[]) {
ventana frame = new ventana();
frame.setVisible(true);
}

public ventana() {
super();
getContentPane().setLayout(null);
final JButton button = new JButton();

button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
try{ the_panel.hola(); }
catch(Exception e){
System.err.println("Errorrrrr :" +e.toString());
e.printStackTrace();}
}
});
button.setBounds(104, 189, 106, 26);
getContentPane().add(button);
}
}



Sin embargo al hacer click en el botón obtengo el siguiente error:
---------------------
Errorrrrr :java.lang.NullPointerException
java.lang.NullPointerException
at ventana$1.actionPerformed(ventana.java:24)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown 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.mouseRe leased(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(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn 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.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
-----------------------------------------------------