Why is my iPhone 3GS phone and charger not compatible with each other?

It has worked for months but now it says "charging is not supported with this accessory"

My iPod does that occasionally aswell try rebooting the devise (power button + home button)

If it was just a one time error message, it may have been plugged in wrong. If you are continually receiving this message try a new charger cable as they wear out from use. Worse case scenario is your charging port in your phone is damaged.