Technically, as soon as you declare an attack, you have to do some sort of attack, and then do an attack you have the correct energy for (the attack phase). If you find it was an honest mistake, and you ask your opponent if you're allowed to take it back, and your opponent allows you to continue your turn, you may then move the appropriate energy and attack.
If you don't have the energy to use the attack, and you try to use it, it doesn't count as attacking. Only when you actually use an attack does it count as attacking.