I would only do a factory reset if nothing else worked; I don't know what you've tried so far.
The first thing I'd do would be to hold the phone upside down and plug and unplug a set of headphones into the jack several times; something might have fallen into the jack that jammed the contacts so they are indicating to the phone that the headphone is plugged in when it's not. This might dislodge that and let it fall out.
If that didn't work, I'd try rebooting the phone: hold the power switch down and pick "power off" from the options, or open the back and pull the battery out.
Only if those didn't work would I try a factory reset.
I hope one of those things works for you; it sounds like it might be a bad headphone jack (hardware), in which case you'll need to exchange the phone under warranty.