Hi,
Does it show that it's charging or do you just see a red X on the battery icon on the bottom right hand corner? Try to reseat the battery, take it off power the laptop on with just the AC adapter then put it back in once the laptop is on and see if it will charge. The fact that it's only working when the AC adapter is connected can also mean that it's the battery that is faulty and replacing it the your best option.