Does this happen while trying to charge wireless or with the original Samsung charger that came with the device? Have you tried using a different cord to see if the symptoms change? Have you inspected the charging port to make sure there isn't any dust or dirt that may be causing this?
I notice it usually happens when you use the phone heavily at the same time when charging or if when wired charging the cable isn't plugged in all the way into the brick. I wouldn't recommend doing the first thing as that could definitely hinder charging. Also if there are any intensive apps still running in the background, that could be a factor as well.
I got that message a few times with different chargers, but the chargers worked fine on my husbands phone of the same model. Ended up being my case. I thought the charger was fully plugged in, but the small cutout left it just a little loose which cause a weak charge.