In most of the cases users get this error message when their SD card gets corrupted. Fortunately, there are some solutions that you can try to fix it:
Solution 1: Simply reboot your phone or camera. So that the app currently using your SD card will stop using it and see if it works or not, if not then try to boot the phone in Safe Mode (this is only applicable to mobile users)
Solution 2: Sometimes, the SD card you are using might be write-protected. The card which is write protected cannot be formatted. So, you have to first remove the write protection, in order to format your SD card.
Solution 3: If both the above mentioned solutions fails then the only option left with you is to use recommended card data recovery tool and one of such powerful software is Photo Recovery Tool. For more information visit - http://www.rescuedigitalmedia.com/fix-cf-card-not-formatted-error