The following method calculates cost. It access other classes when required. Cloud class holds the information for pricing.
However the method is giving me a nullpointer exception at the following line.
BoundaryPrice btp = cloud.getBoundaryPriceMap().get(boundaryType);
The value for totalcost never changes.
Any idea to high light the problem here?
private float getCostForConnector(Connector connector)
{
Cloud cloud = new Cloud("http://amazon.com/europeEC2Clouds#dublinEC2Cloud", dynDesInventory);
List<Port> portList = getListOfPort(connector);
Resource root = findCommonRoot(connector);
Port p1 = portList.get(0);
Port p2 = portList.get(1);
float totalCost = 0.0f;
try
{
String rootBoundaryType = getRootBoundaryType();
Float dataProducedFromP1 = getDataCountForPort(p1);
Float dataProducedFromP2 = getDataCountForPort(p2);
List<String> portOnePathOut = getListOfNetworkBoundary(p1, root);
List<String> portTwoPathOut = getListOfNetworkBoundary(p2, root);
for(String boundaryType: portOnePathOut)
{
BoundaryPrice btp = cloud.getBoundaryPriceMap().get(boundaryType);
if (btp != null)
{
totalCost += btp.getOutPrice(boundaryType) + dataProducedFromP1;
totalCost += btp.getInPrice(boundaryType) + dataProducedFromP2;
}
}
for(String boundaryType: portTwoPathOut)
{
BoundaryPrice btp = cloud.getBoundaryPriceMap().get(boundaryType);
if (btp != null)
{
totalCost += btp.getOutPrice(boundaryType) + dataProducedFromP2;
totalCost += btp.getInPrice(boundaryType) + dataProducedFromP1;
}
}
BoundaryPrice btp = cloud.getBoundaryPriceMap().get(rootBoundaryType);
if (btp != null)
{
totalCost += (dataProducedFromP1 + dataProducedFromP2) * btp.getIntraPrice(rootBoundaryType);
}
}catch(NullPointerException e) {
System.err.println("Caught NullPointerException: ");
}
return totalCost;
}
portOnePathOutandportTwoPathOutlists is nullportListis nullcloud.getBoundaryPriceMap()is nullbtp.getIntraPrice(rootBoundaryType)is numeric wrapper and it is nulldataProducedFromP1ordataProducedFromP2are nullbtp.getOutPrice(boundaryType),btp.getIntraPrice(rootBoundaryType)orbtp.getInPrice(boundaryType)are nullThe list would be much shorter next time when you post the stack trace.