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 circuit board or it could be a part of the motherboard.
NOTE: If it is the battery or the charger cord, do yourself a favor and don't to for aftermarket ones. They may seem like a great deal as they are cheaper, but they also tend to be problematic. While aftermarket can be great for some things, it isn't for these two.