cameraSource.release() throws null pointer exception if detector is null
See original GitHub issuejava.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.vision.Detector.release()' on a null object reference
According to [https://developers.google.com/android/reference/com/google/android/gms/vision/CameraSource.html#release()](Android Documentation) release method completely shuts down this camera source and releases the resources of the underlying detector. But sometimes detector is null and this method throws exception.
Would it not be better to handle camerasource and detector resource separately in that case?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
After returning to activity CameraSource fires null exception
I moved the camera initialization code from onCreate to onResume and protected the camera release like this: mCameraView.getHolder().
Read more >Java NullPointerException - Detect, Fix, and Best Practices
Invoking a method on an object instance but at runtime the object is null. Accessing variables of an object instance that is null...
Read more >com.google.android.gms.vision.Detector java code examples
Releases the underlying receiver. This is only safe to do after the associated thread * has completed, which is managed in camera source's...
Read more >Null Pointer Exception - C2 wiki
A Java Runtime Exception that signals an attempt to access a field or invoke a method of a null object. Note that the...
Read more >https://academic.csuohio.edu/zhao_w/teaching/CIS69...
if (detector == null) { throw new IllegalArgumentException("No detector supplied. ... CAMERA) public CameraSource start() throws IOException { synchronized ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Davehp44 we solved this in a way like:
And then for starting camera:
Nope, I debugged the code to make sure the release is only called once and it is. But the moment I restart it I get this:
Exception thrown from receiver. java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.vision.Detector.receiveFrame(com.google.android.gms.vision.Frame)' on a null object reference at com.imbills.mobile.barcode.ui.camera.CameraSource$FrameProcessingRunnable.run(CameraSource.java:1205)