PDF417 barcode generation - ErrorCorrectionLevel error with 3.2.1 Android

59 views
Skip to first unread message

Chuck Preston

unread,
Apr 15, 2016, 7:52:04 PM4/15/16
to zxing
Setting the error correction level to ErrorCorrectionLevel.L in 3.2.1 seems to be broken in Android.

hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
throws the error: java.lang.ClassCastException: com.google.zxing.qrcode.decoder.ErrorCorrectionLevel cannot be cast to java.lang.Number

You can set it to an integer and it works fine.
hintMap.put(EncodeHintType.ERROR_CORRECTION, 2); // this works

The problem code is in the PDF417Writer class.
I believe this:
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ((Number) hints.get(EncodeHintType.ERROR_CORRECTION)).intValue();
}
should be this:
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ((int) hints.get(EncodeHintType.ERROR_CORRECTION)).intValue();
}

Reply all
Reply to author
Forward
0 new messages