The question

I was at the river swimming with some friends and we had can drinks with us in a cooler. While relaxing in the water I had thrown my empty can onto the river bank and continued to enjoy the water. Shortly an officer appeared and asked us all to come out of the water. I was charged with littering. Should I have been charged when I had not left the area? I go to this swimming spot all the time and I always throw my cans on the bank and I always pick up my cans before I leave.