Since you get an error when running your code from an Android Java application, I would guess that you are missing a permission. It's the camera that you are trying to access, if I am not mistaken, so if you add:
to your AndroidManifest.xml, your application should run fine.