There are several potential causes, but they boil down to two main categories: dns or server configuration.
DNS can be tested with either ping, dig, nslookup, or any number of other tools, depending on what OS you are using. Basically, if you check the ip address for both example.com and www.example.com, they should both have the SAME ip address (group of four numbers separated by periods).
IF THEY DO, your dns is fine in this case (there are other cases where you would want them to do different things, but for right now, just make sure that they have the same ip address).
Next, you need to tell your web server configuration, to tell it that both example.com and www.example.com should use the same files and content. With Apache, this can be done using the ServerName and ServerAlias directives.
Hopefully, this should help.