Either way, it is just a notice, so the code always would work in that kind of error without affecting any functionality. These kind of messages are displayed on the screen, to help programmers to track the potential code issues.

Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.php.net

In your case the notice in the following code:

$username = $user_profile['field_username'];

means that PHP couldn't find field_username key inside the $user_profile array. This could mean several things, such as typos, missing field name, loading empty object or the one without that field, etc.