I think I got you here. This happened to me last year and it took me soooo long to figure out what happened. I think your problem is that you were using some program (in my case, a video player) with your headphones, and you closed your computer, pulled out the headphones, and then opened your computer again and quit that program. What you need to do is open up that specific program again, plug in your headphones, and then while the program is still running, take your headphones out so that the audio plays through the speakers. Thats what worked for me--give it a try.
Yeah, I had this problem too. Turns out it's kinda common - apparently the optical sensor in the headphone jack is confused into thinking something is there when it isn't. What worked for others (and myself) was to take the wood end of a match or something like that and actually put it in the jack and poke around until you hit whatever tiny switch is mistakenly tripped.