Samsung mobile not getting charge when switch on I am using SAMSUNG DUOS2. Its not getting charge when its switched on. But there is no problem in charging when switched off. 

Not charging in both I tried USB as well as wall charger.
Android ver : 4.2.2

I suspect it could be virus problem so with the help of antivirus I cleared some thread. Even after the problem still persist. 

Pls suggest what could be the problem?
Android doesn't need anti virus - see Is an antivirus really needed for Android?
Malware is more of a threat- factory reset may not help as the malware may have lodged itself in the /system partition, which is untouched during factory reset. See Can a Factory Reset fix Malware Problem?


That out of the way, your problem may be due to:


User installed applications misbehaving
Malware (though I haven't read of any malware doing this yet)
OS corruption (of drivers pertaining to charging)


To rule out 1, put your device in safe mode. If the charging behaviour is fine, then you would need to uninstall all installed apps and re-install one by one checking that problem doesn't surface. Painful, yes, to avoid that  jump to steps in  next para

If the problem persists, you have no other option but to flash stock ROM. Instructions for flashing here. Stock ROM mentioned there is Indian, which should work fine for you or you can download latest stock ROM from sammobile. Make sure you take a backup though- if your device is not rooted Full Backup of non-rooted devices would help else use apps from play store

That should fix your problem, unless it is hardware related (very unlikely)