The way to avoid these situations, and the fall-out from them, is to educate boys and girls to respect each other, and be mindful that what is meant in a remark, or behaviour, is not always what is received.
Remember Dave Lee Travis, genuinely baffled that women did not appreciate his being a 'cuddly tactile person' as he saw himself?
What the hairy sex-pest failed to understand is that, just because he liked laying hands on any and every woman within arms' reach did not equate to every one of them thinking it was just big cuddly old Dave, so it's absolutely fine.
People need to learn proper behaviour around each other, and to understand that harmless banter delivered can be sexual harassment received - and basically learn some dignity and respect for people around them, and more importantly, for themselves.