It is rather common for you eyes to feel hurt if you stare on something for a long time, especially your eyes will hurt when you focus on something that is close. Because when you stare on something, your eyes blink less often, so your eyes will be very tired and the light exposure makes your eyes hurt. You just need some rest for your eyes and you can try putting ice over my eyes to relax them.
It would be better and easier to diagnose if you could provide more backgrounds information. I am not sure whether you have any eye infection, inflammation or allergies recently. If there is no any other condition or disease associated, then you might need to consider the muscles problem which control eye rotation. No matter you need to look up-close or at distance, your muscles at back of eyes need to overcome certain diopter of convergence power in order to get focused. Maybe you should get eye specialist to check your diopters of eyes. You might need a new pair of eyeglasses prescribed. Take frequent breaks to relax your eye muscles. Do some eye exercises to enhance the alignment and power of muscles which rotate eyes. It can help strengthen the capability of focusing and alignment.