I can print the results if they are in their own method but when I try to call the results of the array from my printReport method I get a null pointer exception
Exception in thread "main" java.lang.NullPointerException
at DiceSimulation.printReport(DiceSimulation.java:37)
at LundeLeviProg2_3.main(LundeLeviProg2_3.java:33)
is really needed inside the DiceSimulation Class ?Scanner stdIn = new Scanner(System.in);
public int rollGenerator() int[] rollCounter = new int[numberOfRolls + 1];
Campbell Ritchie wrote:No, I don't think starting at 1 in an array is the cause of the NPE. It is an int[] array, so it cannot contain nulls, only 0s. The NPE was caused by the array itself being null.
Good idea about the rolling method.
Campbell Ritchie wrote:You might get ArrayOutOfBoundsExceptions from that sort of loop, but in this case, I would agree with the trick of making the array "one too big." That has been done correctly, too.
You down with OOP? Yeah you know me!
Levi Lunde wrote:
The output is functional but I was wondering how to line up rolls, frequency, and graph with the results? Or if it's even possible?
Campbell Ritchie wrote:I think you will need to go back to that Java Tutorials page and look at format Strings again; the example you showed won't work, I am afraid.
Don't get me started about those stupid light bulbs. |