May be the object is not being created properly, debug with a try-catch block.