Originally Posted by
DavidFongs
Can you post the stack trace from the NPE?
I posted it as a link, but here, once more.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at intro.JFrameExt.jtfActionPerformed(JFrameExt.java:336)
at intro.JFrameExt$3.actionPerformed(JFrameExt.java:183)
at javax.swing.JTextField.fireActionPerformed(Unknown Source)
at javax.swing.JTextField.postActionEvent(Unknown Source)
at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(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)
Line numbers do match. Here is first one
179: //Register this as the listener with JTextField object
180: jtfPropValues[j].addActionListener(new java.awt.event.ActionListener() {
181: public void actionPerformed(java.awt.event.ActionEvent e) {
182: // reflect changes
183: jtfActionPerformed(e);
184: }
185: });
Here is second one
331: //Get the set method object.
332: Method mset = pd[i].getWriteMethod();
333:
334: //Invoke set method and pass it target bean and parameters.
335: try {
336: mset.invoke(targetBeanObject, params);
337: }
And here is the jtfActionPerformed
/** text field actionListener event begin*/
public void jtfActionPerformed(ActionEvent e) {
int i;
String propName="", propValue="";
//Determine the name, value and index of the property that changed.
for (i=0; i<jtfPropValues.length;i++) {
if (e.getSource()== jtfPropValues[i]) {
break;
}
}
//Get the property name and the property value from the
//JLabel and JTextfield corresponding to the i value.
propName = jlbPropNames[i].getName();
propValue = jtfPropValues[i].getText();
//Note that the property index for the above property in the pd
//array is the same. So you can go to that index in pd array and
//access its property type .
Class propType = pd[i].getPropertyType();
//Get the property type as a String
String propTypeName = propType.getName();
//Create Object array for storing parameters
Object[] params = new Object[1];
//Depending upon property name, create correct parameter object.
if (propTypeName.equals("int")) {
params[0] = new Integer(Integer.parseInt(propValue));
}
else if (propTypeName.equals("double")) {
params[0] = new Double(Double.parseDouble(propValue));
}
else if (propTypeName.equals("boolean")) {
params[0] = new Boolean(propValue);
}
else if (propTypeName.equals("java.lang.String")) {
params[0] = propValue;
}
//Get the set method object.
Method mset = pd[i].getWriteMethod();
//Invoke set method and pass it target bean and parameters.
try {
mset.invoke(targetBeanObject, params);
}
catch (IllegalAccessException ex) {
}
catch (IllegalArgumentException ex) {
}
catch (InvocationTargetException ex) {
}
}
/* actionListener event end */
Originally Posted by
Copeg
I do not see any code which intializes the PropertyDescriptor array - which would equate to a NullPointerException.
Line 34:
private PropertyDescriptor[] pd = null;
Then 250-251
//Get an array of PropertyDescriptor objects from BeanInfo object.
pd = bi.getPropertyDescriptors();