As scary as a lens error might seem, there are some easy fixes. Before trying any of them out, however, first take a good long look at your camera warranty and maybe have a chat with the company. If the lens error will be covered under the terms of the warranty, go for it. Even some of the simple fixes mentioned below might void the camera warranty. Frankly, however, it's unlikely that a lens error will qualify for the warranty.
Try just some basic things first—just to make sure it's actually the lens that's broken. Replace the batteries with fresh ones. Failing that, replace the memory card.
OK. So it's still not working. Try plugging the camera via the audio/video (AV) cable into a computer or other USB power source. This might provide just enough of an extra boost of power to override any particulates that might be trapped within the lens mechanism.
Still not working? Trying turning the camera on and off in a variety of positions – face up, face down, at different angles. Doesn't work? Try blowing compressed air into the gaps around the barrel of the lens. The idea is, again, to knock loose any particulates that might be getting the mechanism stuck.
Uh-oh. Still broken? This is where these suggestions might void the warranty. Try—carefully—tapping the lens with rubber or something hard yet padded, or the entire lens barrel against a hard surface. Excessive force is a definite no-no, as you might cause more damage than the lens error itself.
Forcing the lens open might be a good bet. Again, being careful as to not cause even more problems is an absolute must. Try manipulating the lens while hitting the power button—pulling, twisting, tugging, pushing, in the hopes of getting the guide pins to snap back into place.
If you've got a little technical know-how and a little patience, try removing the lens and cleaning out the interior a bit with compressed air.
You might also want to try looking up lens error repair information specific to your camera or camera brand. For instance, here is a whole site dedicated to the Canon E18 lens error and how to fix it.
If all this fails... well, depending on the quote for a repair by the camera company, it might just be better to buy a whole new camera, if the alternative is having no camera at all. Fixing a lens error is invasive and more than a little dodgy, so you might be out of luck.