What version? What kind of a machine? What OS? How much memory? All of these things can effect stability. Only frames that need to be cached will show up in the green bar so it's not unusual to have holes. The length of the preview depends on the available ram and the project size. Rendering to some codecs is more problematic than others, especially if you have installed some 3rd party codec packs.
After effects cs4 I am on a windows vista. I am not sure how much memory but what could I do to solve this?
the green bars you see are the cache indicators and they mark the frames that are precomputed and stored in RAM or disk cache. Whenever you make a change to a layer you'll see that they'll go "ungreen" as those frames have changed from what AE had in cache. Also, AE can only store a limited number of frames in RAM, limited by the size of your RAM, so when it needs to compute new frames it starts clearing the old previews to make room. If you turn on disk cache in preferences, you'll see also blue bars. Those mark the frames stored in disk cache instead of RAM, but it's pretty much the same thing, previews of those respective frames (not the final output).
As for the crashing on export, this could be caused by a number of things, including faulty codecs as Rick pointed out, bad graphics card drivers, bugs, etc. Make sure you have latest updates for Win and AE, and latest drivers installed.
Last but not least, buying a 1000$ program doesn't grant you immediate knowledge of it, nor a personal trainer for it, more as AE is a pretty complex program and will take a while to learn it. However there are lots of resources (some free, some paid) to help you learn, including this community forum. Diving into the program and start using it won't get you very far, you have to start with the basics, and learning the interface first will help you in the long run.
I assume you're fairly new with this program, so you can start you learning here: http://blogs.adobe.com/toddkopriva/2010/01/getting-started-with-after-eff.html
AFTER YEARS OF SEARCHING...
No, I'm kidding. But after a few months the most simple minded idea hit me. Ok. So right underneath that preview screen is a graphics quality drop down menu. By default it is on full, but I clicked on it and selected "half" and the graphics changed. I personally did not see any significant change in graphics quality but that isn't the point. I could now scrub waaaaaaaaaaaaaay more media than I used to be able to. And I'm sure that if I changed it down to a quarter graphics it would have gone even farther.
Nice try after effects team, but I got this one. I would suggest using my answer in the future if anyone has the same problem.