Well it could be a few things.
1. It could be the charger cord. If it isn't putting out the correct amount of power, then it may well run the device, but not charge the battery at the same time. A good way to test that is to turn the laptop completely off (not sleep or hibernate) and plug it in to charge to see if it will charge then. If it does charge, the cord is your problem.
2. It could be the battery is going (they do after a while), if that is the case then it won't charge even when the laptop is turned off.
3. If it is actually both of them, the laptop may not charge, even when it is turned off, when the battery is in.
4. If it is neither the cord or the battery, it could be the charging circuit. This can be on its own...