Double check (using the debugger) that all the objects are initialized before you call their methods. The code you posted seems ok, so the problem is likely elsewhere.
Is the exception code 0xC0000005 (access violation)?
Also, it is a good practice to check the HRESULTs of the D3D calls to determine if something went wrong. That code should work as is, though.