Like most people, your immediate response to someone's problem might be trying to offer a solution.
And this is a natural response – after all, who doesn't want to solve a friend's problem?
Unfortunately, this response usually backfires. When a friend comes to you, they are normally looking for support, not solutions. They want to be able to talk about the issue; they want to receive encouragement and validation – they might even want a safe place to cry.
But when you immediately offer advice or try to fix the problem, you prevent your friend from finding the support they are looking for. Once they've had the opportunity to share their emotions with you, then they might be open to hearing your advice. But when they first open up to you, they need you to listen, not to fix it.
Honestly, your friend has probably already spent an awful lot of time thinking through their problem. While it's possible that you've thought of a solution that hasn't yet occurred to them, it's unlikely.
So be humble when offering advice.
Ask them if they want to hear your advice before you start giving it, and if they don't like your advice, drop it. They are the experts on their own problem, and if you insist on telling them what to do, you will just irritate them and make their situation worse.