William Willi William Willi - 3 months ago 14
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() .

@Override
public void onPause() {
super.onPause();

mScannerView.stopCamera();

}


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

Answer

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){
   mScannerView.stopCamera();
}
Comments