zxing/zxing · error · IllegalArgumentException
Requested dimensions are too small: ${width}x${height}
Error message
Requested dimensions are too small: ${width}x${height} What it means
Error "Requested dimensions are too small: ${width}x${height}" thrown in zxing/zxing.
Source
Thrown at core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java:63
}
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
}
if (hints.containsKey(EncodeHintType.MARGIN)) {
quietZone = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
View on GitHub (pinned to 19aa2d8254)
Solutions
- Request output dimensions large enough to contain the QR symbol including quiet zone.
- Pass 0x0 (or omit dimensions) to let the writer pick a suitable size.
When it happens
Trigger: Thrown at core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java:63 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zxing/zxing@19aa2d8254 (2026-08-14).
Data as JSON: /api/errors/a69f9573d716728b.
Report an issue: GitHub.