Default My galaxy s 4g keeps turning off.

I recently started using a galaxy s 4g. Well, it worked perfectly until i plugged it into the charger. Everytime i connect my charger the phone shuts off but when i disconnect the charger it turns back on and works perfectly fine. why?