java - Android Manifest Permissions issues -


i followed tutorial online how create simple app can switch on , off phone's cam-light.

<manifest....>  <uses-permission android:name = "android.permission.camera"/>     <uses-feature android:name = "android.hardware.camera"/> </manifest> 

this in android manifest. problem: crashes when press on button (made me, in application)

stack trace:

07-17 22:27:13.990: e/androidruntime(1775): fatal exception: main  07-17 22:27:13.990: e/androidruntime(1775): java.lang.nullpointerexception  07-17 22:27:13.990: e/androidruntime(1775): @ com.example.salpa.mainactivity$1.onclick(mainactivity.java:33)  07-17 22:27:13.990: e/androidruntime(1775): @ android.view.view.performclick(view.java:4204)  07-17 22:27:13.990: e/androidruntime(1775): @ android.view.view$performclick.run(view.java:17355)  07-17 22:27:13.990: e/androidruntime(1775): @ android.os.handler.handlecallback(handler.java:725) 

another strange thing: when install app, there no details permissions requiring.

"the application can acces following on phone:" , there's nothing. (despite permissions in tutorial shows application needs permision camera.)

can please me, thanks.

setcontentview(r.layout.activity_main);  button aprinde =(button)findviewbyid(r.id.aprinde); //button sting = (button)findviewbyid(r.id.sting);  cameraobj = camera.open();  aprinde.setonclicklistener(new view.onclicklistener() {      public void onclick(view view){          camera.parameters cameraparams = cameraobj.getparameters();          cameraparams.setflashmode(camera.parameters.flash_mode_torch);          cameraobj.setparameters(cameraparams);         cameraobj.startpreview();       }  } ); 

your app crashing because running on emulator, doesn't have back-facing camera.

the documentation camera#open():

creates new camera object access first back-facing camera on device. if device not have back-facing camera, returns null.

you can fix crash checking null.

public void onclick(view v) {     if (cameraobj == null) {         return;     }     camera.parameters cameraparams = cameraobj.getparameters();     cameraparams.setflashmode(camera.parameters.flash_mode_torch);     cameraobj.setparameters(cameraparams);     cameraobj.startpreview(); } 

you should out setparameters crash if device doesn't have flash.

public void onclick(view v) {     if (cameraobj == null) {         return;     }     camera.parameters cameraparams = cameraobj.getparameters();     if (cameraparams.getflashmode() == null) {         return;     }     cameraparams.setflashmode(camera.parameters.flash_mode_torch);     cameraobj.setparameters(cameraparams);     cameraobj.startpreview(); } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -