Thanks a lot Diego.
I fixed it by checking for an entry before putting something into the previous map.
Btw: I can't change the condition in the while loop because it then only works for paths with an even length. In all cases with a path of odd length one queue will be empty before the other.
Again, thank you very much for your effort and help. I appreciate that.