I changed my username and now I cannot play online

Solution 1:

It's caused by remaining logged in after changing your name. Not everything is updated.

You need to open the Minecraft launcher, log out, and log back in again (i.e. you need to enter your user and password again). This should fix it.