Mega 2560 and LCD 1602 got error messages when upload
This doesn't look like an error with the LCD or the sketch. The error message means that your Arduino IDE (or rather the underlying avrdude program) cannot connect to the Arduino board. So check you setting and your connections to the board. If this error persist, try to get more information about it, and then ask a more targeted question (which board do you have, how is it connected, can you program it at all, which IDE version do you use, and so on).