On the line
if(vDec.getRoute()[(int)IndexVeh.peek()].isEmpty())
You will get an EmptyStackException
if and only if IndexVeh
is empty when that line is executed.
Pergunta
I have the following part of code to initialize an array of stack:
vDec.setRoute(new Stack[vDec.getIndexes().length]);
for(i=0;i<vDec.getIndexes().length;i++){
vDec.getRoute()[i]=new Stack<>();
}
I get java.util.EmptyStackException
when I am checking if it is empty inside a while
loop but not before it. So for this part:
if(vDec.getRoute()[(int)IndexVeh.peek()].isEmpty()){
System.out.println("it works");
}
while((cDec.getVisitedBy()[crtCust]==-1)&&(!Distance.empty())){
if(vDec.getRoute()[(int)IndexVeh.peek()].isEmpty()){
do something
I first get as output it works
and then the exception.
Solução
On the line
if(vDec.getRoute()[(int)IndexVeh.peek()].isEmpty())
You will get an EmptyStackException
if and only if IndexVeh
is empty when that line is executed.