Fix NPE

Fixes https://github.com/appium/appium/issues/628
Merge pull request #632 from bootstraponline/fix_npe

Fix NPE