You need to check that the field has a value before outputting the div as my code above shows.
I do not know why you got an error when you tried it, I do not see anything wrong with the code, but that does not mean I’m not missing the mistake.
https://codex.wordpress.org/WP_DEBUG