Hallo,
im Konstruktor einer Klasse (View) erzeuge ich folgendes Objekt:
Außerhalb des Konstruktors möchte ich mittels eines Getters das Objekt verfügbar machen:
Der Controller soll sich das Objekt zum Beispiel holen und an das Model weiterleiten:
Doch leider bekomme ich immer folgende Fehlermeldung, was mache ich falsch?
im Konstruktor einer Klasse (View) erzeuge ich folgendes Objekt:
Java:
cal = new GregorianCalendar();
cal.set(2016, 1, 1);
Außerhalb des Konstruktors möchte ich mittels eines Getters das Objekt verfügbar machen:
Java:
public GregorianCalendar getcal() {
return cal;
}
Der Controller soll sich das Objekt zum Beispiel holen und an das Model weiterleiten:
Java:
public DefaultTableModel getTablePlanungModel() {
tablePlanungModel = databaseModel.createTablePlanungModel(getcal());
return tablePlanungModel;
}
public GregorianCalendar getcal() {
cal = viewEinsatzplan.getcal();
return cal;
}
Doch leider bekomme ich immer folgende Fehlermeldung, was mache ich falsch?
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at de.xxx.swing.mvc.ids.ControllerViewEinsatzplan.getcal(ControllerViewEinsatzplan.java:46)
at de.xxx.swing.mvc.ids.ControllerViewEinsatzplan.getTablePlanungModel(ControllerViewEinsatzplan.java:40)
at de.xxx.swing.mvc.ids.ViewEinsatzplan.createTable(ViewEinsatzplan.java:117)
at de.xxx.swing.mvc.ids.ViewEinsatzplan.<init>(ViewEinsatzplan.java:102)
at de.xxx.swing.mvc.ids.ControllerViewEinsatzplan.<init>(ControllerViewEinsatzplan.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at de.xxx.swing.mvc.ids.Controller.handleMenu(Controller.java:27)
at de.xxx.swing.mvc.ids.View$MenuActionListener.actionPerformed(View.java:83)
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.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)