William Willi William Willi - 1 year ago 103
Android Question

i get null pointer NullPointerException from onPause() method

i have made an Qr-Scanner now the activity has button. if i click the button it opens the scanner so i'm doing good with it, but if i go back to the previous activity without clicking the button i get the NullPointerException from the onPause() .

public void onPause() {



if i go to previous activity without opening the camera then it is giving the error. someone help me

Answer Source

If you want to prevent stop() method from being called if the camera is not started, you must use a boolean expression to check.

inside onPause method:

if(mScannerView != null){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download