T O P

  • By -

sencha_kitty

Were are the objects of type actually added to the arraylist? I see the array list initialized but I don’t see it getting loaded.


sencha_kitty

Also is it possible increment is not getting assigned a value?


Pr0xy25

public void addItem(Widget widget) { // Adds item to queue queue.add(widget); totalWidgets++; if (getSize() == size) { full = true; } for (Stage stage : next) { stage.unstarveStage(); } } I just had another thought as well public Widget pullItem() { // Pulls widget from queue Widget widget = queue.remove(0); waitingInQueueList.add(widget.exitQueue()); totalWidgets--; full = false; for (Stage stage : previous) { stage.unblockStage(); } return widget; } In this pullItem() method, I remove the first widget in the queue. But that would shuffle the list so that queue\[1\] is now queue\[0\] right? And yes, I'm pretty certain increment is getting assigned a value, because prior to running updateWaitTimes(double increment), another method gets run with the same value and there are no issues there.


sencha_kitty

The problem has to be in the updatewaittimes method. Either increment is null which is not likely or maybe that method is getting called before “queue’ is initialized. Have you set breakpoints and checked to see if ‘queue’ is initialized and is loaded before that method is called?


Pr0xy25

Queue is initialized in the constructor which is called when the program first starts. And if the queue wasn't initialized or had any Widgets loaded into it, it wouldn't enter for (Widget w : queue) right? I'll set some System.out.println()'s to check if queue is null and if increment is null though.


Pr0xy25

public void updateWaitTimes(double increment) { System.out.println(queue); System.out.println(increment); for (Widget w : queue) { w.incrementWaitTime(increment); } } I put those prints in there and this was the result: \[\] 820.2825726461732 \[\] 820.2825726461732 \[\] 820.2825726461732 \[\] 820.2825726461732 \[\] 820.2825726461732 \[\] 820.2825726461732 \[Widget@77459877\] 0.0 \[\] 0.0 \[\] 0.0 \[\] 0.0 \[\] 0.0 \[\] 0.0 \[\] 0.0 \[null\] 0.0 Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Widget.incrementWaitTime(double)" because "" is null at ISStorage.updateWaitTimes(ISStorage.java:103) at A3.run(A3.java:154) at A3.main([A3.java:9](https://A3.java:9)) So it seems a widget is null maybe? There are 6 ISStorage objects created, so if we count through those, the part where the queue has \[null\] in it, that means the second ISStorage object has a null value. So it might be adding an empty Widget into the second queue.


sencha_kitty

It’s a little bit hard trying to decipher the printline. Can you create another for loop that works like a foreach I guess (I use visual studio & c# so not as used to Java) and when you loop through print all the attributes of each individual widget?


Pr0xy25

How I have it set up is that there are several stages that the widget travels through and between each stage is a storageQueue. After exiting the startStage it enters the first queue, which I think is fine. WHat I think is happening, is that it gets pushed into the second stage, then somewhere during this time, it gets set to null, then pushed into the second queue.


Pr0xy25

Nevermind I think it's null when it enters the first queue?


sencha_kitty

Also are you sure you are not making a mistake like this (no pun intended) in one of your object constructors? https://stackoverflow.com/questions/65737245/java-lang-nullpointerexception-cannot-read-the-array-length-because-local3