MInecraft Java infinity enchant not working

I know this might come across as obvious, but try to make sure you have arrows in your inventory. It could also help to upgrade or downgrade your version of Minecraft if possible. This may stop you from playing on servers, but I believe it would fix the problem on singleplayer. if you can’t change the version maybe try this article on it.