2n2222 Getting hot

Hello
I circuited a 5v solenoid and a 2n2222 as shown in the attachment.
When uploading a simple solenoid blink program, it functions properly but the 2n2222 get incredibly hot very fast.
I was wondering if I made any errors and what I could do to reduce heating.

Sorry if this sounds basic I'm new to using transistors and such.

How to post an image

You need to have a reverse biassed diode across the solenoid, otherwise it will kill the transistor with back EMF. Any common 1A diode will do, such as 1N4001 etc.

That isn't the cause of your problem however. You are trying to implement a high side switch with an NPN transistor, which won't work.

Emitter to ground, collector to solenoid, solenoid to +5V. 220Ohm resistor between Arduino out out pin and base. Don't forget the diode!

If you are new to transistors, don't guess a circuit!

This is the basic circuit you'll see nearly everywhere you search:

For high current loads make the base resistor lower in value, perhaps down to 150 ohms, but for most
relays you don't need to go quite that low. Arrange for the base current to be about 5% to 10% of the relay
current.

The diode is absolutely vital, omit it and the transistor will be destroyed. Yes it does go that way round,
and it goes across the relay coil, not the transistor (a common mistake).

Thanks for the help.
Managed to get it working without heating up too much.