It could be a pulled muscle or a cracked rib. Did you fall recently? Have you had coughing fits? Did you sleep wrong? (That last question, if you think about it, is a funny question. How do you know if you slept wrong? You were asleep!) But seriously, it could be a number of reasons. Are you a smoker?
What did you eat recently? Not a stupid question really. Is the pain continuous, or does it come and go? For how long? Do you feel feverish? Does your back (upper) ache or hurt at all? Any pain in back area around shoulder blades or around rib cage? These are the symptoms I had when having a gallbladder attack. Any pain in the abdominal area, should be checked out immediately, just to make sure not serious.
It could be built up congestion , not to scare you but I had walking Pneumonia when that happened to me . Though it could be other things as well . Go check it out with your family doctor