Sharp pains in sides?

lately after I masturbate or have sex, I get these really bad sharp pains in the sides of my stomach. it continues for at least an hour and hurts when I stretch or move the wrong way. does anybody know what this could be?