Welcome to the Forum, although I am sorry to hear your problem. Based upon a number of earlier threads on some related topic:
- Try another SD card as suggested. Preferably a Sandisk Class 6 or above.
- Make sure that your batteries are 100% charged or better brank new Lithium batteries.
- Update your firmware to have the latest.
The K-x with the earlier firmware version was very susceptible with partially-discharged batteries. The latest firmware solved the problem, but your camera might not have come with it. The new firmware is free. You must download it from Pentax, expand the file and copy the file to the SD card. Then start follow the Pentax instructions.
Hope that the suggestions will assist....