Samsung Galaxy Nexus doesn't detect charger This happened yesterday night first. My phone's battery was very slow, so I decided to charge it. It didn't start charging after plugging in the charger. Frustrated, I kept trying with different USB cables and laptop USB ports and wall adapters. I tried with my wife's phone too, and it started charging.
Eventually, the phone died, and I plugged it in anyway. After that, it started showing the battery symbol and the charging animation (as it always does when charging when switched off), but the animation would stop and the display would go off, and the entire symbol and charging animation would repeat. This would keep repeating.
I gave up, stopped charging it and when to sleep.
When I woke up in the morning, I decided to give it another shot, and it just started working! I had to go to work, so it could only charge to around 50% before I left. I tried charging in the office with the USB port, but it very slow, almost not charging at all, just keeping up with the discharge!  

I just got back home a little while ago, and it's the same story as last night. It is refusing to charge, and there is 10% battery left! 

A few days ago, I left my phone in my pocket when I was on the treadmill in the gym, and it was getting tossed around in the pocket a lot.. I don't know if this has anything to do with it.   

Will replacing my battery help? Is there anything else I can do? Software reset?

Edit: It just started charging now. It was just kept switched on and plugged into my laptop, with airplane mode enabled (as battery is low, and I live in a bad area with poor reception). I didn't even try to reinsert the charger. Looks like I am going to sleep a little more peacefully tonight, but I am still concerned as to why this happens, and would like to fix it.
This sounds like a loose usb port on the phone. The microUSB port on smartphones are delicate things and can easily become loose and no longer reliably charge. If you use your phone or leave it connected but with the power connection taut (like if it's plugged into the wall and fully extended so the power cord is putting pressure on the microUSB port), over time this can and WILL loosen (or even break) the solder joints that connect the MicroUSB port to the circuit board. Eventually leading to a scenario like you're seeing now.

Hopefully your phone is still under warranty, as a mainboard replacement is likely in order here...Unless you're VERY skilled at micro-soldering work, then you could take the phone apart and see if you can re-solder the loose/broken connects.