I have this piece of code which is throwing a Null Pointer exception at the commented line.. I think that it may be because I haven't initialized the array ParentInterfaces am I right??...the problem is since this array may contain a number of elements ranging from 2 to 30 I would not like the idea of initializing it in constructor second if I do that woudn't it result in a memory leak in function2 as I have an object there whose reference I am passing to another function????...Is there any other alternative available???
public class Class {
public String modifier;
public String name;
public Class parent;
public Interface[] parentInterfaces;
public Method[] memberFunctions;
public Class[] nestedClasses;
public Interface[] nestedInterfaces;
public Field[] memberData;
public int methodCount, classCount, interfaceCount, fieldCount, parentInterfaceCount;
public Class (String classModifier,String className)
{
modifier=classModifier;
name=className;
methodCount=0;
classCount=0;
interfaceCount=0;
fieldCount=0;
parentInterfaceCount=0;
}
public void setParentInterfaces (Interface[] interfaces)
{
while (interfaces[parentInterfaceCount] != null)
{
// This is the line which throws the NPE
parentInterfaces [parentInterfaceCount] = interfaces [parentInterfaceCount];
parentINterfaceCount++; } } Now the piece of code which results in a call to this function is: (It belongs to a diff function in a diff class)
// Prev Code
else if (child.getNodeName()=="ParentInterface")
{
Iflag=1;
//Element ele=(Element)child;
JOptionPane.showMessageDialog (null, "Parent Interface found" + child.getTextContent () + "for " + classes[i].name);
parentInterfaces[parentICount] = new dataObjects.Interface (child.getTextContent ());
// classes[i].parentInterfaces[parentICount] = new dataObjects.Interface (child.getTextContent ());
parentICount++;
}
}
classes[i].setParentInterfaces (parentInterfaces);
classes[i]
getting set? – CoolBeans May 4 '11 at 22:05