When I try to output the strings from the modules
public class Module
{
public String moduleName;
//public String moduleResults;
public void setModuleName(String aModuleName)
{
moduleName = aModuleName;
}
public String getModuleName()
{
return moduleName;
}
}
using
public void displayModules()
{
for (int i = 0; i < moduleArray.length; i++)
{
System.out.println(moduleArray[i].getModuleName());
}
}
I get a NPE when the array(of length 4) is not full and when it is full nothing is outputted when I use the method. I’m using blueJ if that makes a difference.
Your NPE comes from trying to call
getModuleNameon a null reference.As to why nothing gets printed when you do have valid elements, I suppose you might not be setting the names correctly, elsewhere.