I have tried to assign a value to a bean class property through a jTextfield and retrive it (Using netbeans).
but when i try this
the following exception has been thrown
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at se.Log.jButton1ActionPerformed(Log.java:79)
at se.Log.access$000(Log.java:19)
at se.Log$1.actionPerformed(Log.java:46)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
mohammad mahdi ghaseminya
Greenhorn
Joined: Jun 15, 2011
Posts: 6
posted
0
Hi,
Are You create first object of your bean?
you must create an instance of it in your main class's constructor.
Note that above code is not foolproof and in fact, is quite vulnerable. But I have just added one line to your code, to show what could be done. If you are to use this professionally for some project, you might wanna put some checks on what value is entered through jTextField1 because it may contain a lot of special characters, multiple decimal points, letters, etc.
In line 04 (refer code above), I have put a label on the frame which will be modified to whatever value user enters from the textfield.
Please refer to attachment to see an example.
Regards,
Ashutosh
SCJP 6, next stop - OCPJWCD!
Kasun Wixkramanayake
Ranch Hand
Joined: Feb 09, 2010
Posts: 46
posted
0
@mohammad mahdi ghaseminya
i have created a bean class instance inside the Action but still get the error message
mohammad mahdi ghaseminya
Greenhorn
Joined: Jun 15, 2011
Posts: 6
posted
0
No!
if you create null object you cant reach attributes!
also if you want to use this bean in your main class it is useful to create it in construction,
Kasun Wixkramanayake
Ranch Hand
Joined: Feb 09, 2010
Posts: 46
posted
0
@mohammad mahdi ghaseminya
thank you brother.it works