Good advice so far.
As already stated, you can only avoid getting hurt by avoiding the situations all together.
As time goes on, you will gain more and more wisdom and knowledge on how to deal with relationships.
It's cliche, but it's like learning to ride a bike. You're going to fall a few times, get some bruises and whatnot, but with practice you'll master the skill.
Life is all about learning through trial and error.
Looking back, if I hadn't made the mistakes I did, I would have never become the person I am today. You'll see that each mistake you make, will help you to learn and understand more about not only the situation, but also yourself.
Broken hearts are part of the process to becoming aware of what you do and don't want out of life/relationships.
Anyway, basically don't rush into things. I've found that developing a friendship is key to a strong based relationship. Once you have that to stand on, building up is easier.
So keep it slow, and in time you'll know when to give in and let the walls down.