The "E2" error indicates that the dryer's thermistor has failed. The thermistor is used to properly heat the dryer and your dryer will have no heat without it.
Sometimes the dryer just has a bad reading and the error will appear on accident. Unplug the dryer for a minute and plug it back it. If the error reappears, then it's real. If it disappears, then it was a glitch.
Replace the thermistor on your dryer. Use your model number and the Whirlpool customer service website to find the proper part and installation instructions. Or, arrange for a professional to install the part.
The "E2" error is the same as the "E1" error on Whirlpool dryers. They both indicate a thermistor failure and appear only on the Duet models of Whirlpool dryers.