Cmon! You can still be happy even if you lost your job, if you failed your exam, even if you didn't please your parents, and even if you're broken hearted. All you have to do is to set your mind that nothing is permanent! Your loneliness isn't permanent.
If what causes you loneliness is memories, here is what Joel Osteen said,
Bad memories will play the most often, but just because the memory comes up doesn’t mean you have to watch it. Change the channel.
And be happy! Because God wants you to rejoice always ( Philippians 4:4)