microg/GmsCore · error · IllegalArgumentException
No detector supplied.
Error message
No detector supplied.
What it means
CameraSource.Builder's constructor throws IllegalArgumentException when the supplied Detector is null. The detector processes camera preview frames, so the builder fails fast rather than producing a CameraSource that cannot do anything at start().
Source
Thrown at play-services-vision-common/src/main/java/com/google/android/gms/vision/CameraSource.java:192
if (camera != null) {
camera.takePicture(shutter::onShutter, null, null, (data, camera) -> jpeg.onPictureTaken(data));
}
}
}
/**
* Builder for configuring and creating an associated camera source.
*/
public static class Builder {
private CameraSource cameraSource = new CameraSource();
/**
* Creates a camera source builder with the supplied context and detector.
* Camera preview images will be streamed to the associated detector upon starting the camera source.
*/
public Builder(Context context, Detector<?> detector) {
if (context == null) throw new IllegalArgumentException("No context supplied.");
if (detector == null) throw new IllegalArgumentException("No detector supplied.");
this.cameraSource.context = context;
this.cameraSource.detector = detector;
}
/**
* Creates an instance of the camera source.
*/
public CameraSource build() {
return cameraSource;
}
/**
* Sets whether to enable camera auto focus. If set to false (default), the camera's default focus setting is used. If set to true, a continuous video focus setting is used (if supported by the camera hardware).
* Default: false.
*/
public Builder setAutoFocusEnabled(boolean autoFocusEnabled) {
this.cameraSource.autoFocusEnabled = autoFocusEnabled;
return this;View on GitHub (pinned to 157c9d86ac)
Solutions
- Create the detector before building the CameraSource and verify it is non-null
- Handle detector-creation failures explicitly instead of passing the null result downstream
- Check the order of initialization so the detector exists before the builder call
- Wrap in a null check that produces a clearer app-level error
Example fix
// before
Detector<?> detector = maybeCreateDetector(); // may return null
CameraSource source = new CameraSource.Builder(context, detector).build();
// after
Detector<?> detector = maybeCreateDetector();
if (detector == null) throw new IllegalStateException("Detector unavailable");
CameraSource source = new CameraSource.Builder(context, detector).build(); Defensive patterns
Strategy: validation
Validate before calling
if (detector == null) throw new IllegalStateException("Detector must be created before building CameraSource"); Type guard
boolean canBuildCameraSource(Context ctx, Detector<?> d) { return ctx != null && d != null; } Try / catch
try {
CameraSource.Builder b = new CameraSource.Builder(context, detector);
} catch (IllegalArgumentException e) {
// detector creation failed upstream; surface the real cause
} Prevention
- Create detectors eagerly and handle their failure paths explicitly
- Don't pass lazily-initialized fields that may still be null
- Log why detector creation returned null
When it happens
Trigger: Calling new CameraSource.Builder(context, null) — commonly because detector construction failed silently, a factory method returned null, or the detector was conditionally created for a feature that is disabled.
Common situations: Lazy-initialized detector field still null at builder time; barcode/face detector creation skipped when dependencies (e.g. model download) failed; wrong variable passed.
Related errors
- No context supplied.
- null camera target
- Could not find requested camera.
- Could not find suitable preview frames per second range.
- Cannot advance the iterator beyond
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/6b80dea552fbca28.
Report an issue: GitHub.