I had to go to File | Project Structure... | Modules and hit the + to add my current project as a module. After this the I could successfully run the code.
File | Project Structure... | Modules
+