alexzhirkevich/custom-qr-generator

com.google.zxing.WriterException

Closed this issue · 5 comments

Describe the bug
Caused by com.google.zxing.WriterException:
at com.google.zxing.qrcode.encoder.Encoder.chooseVersion (Encoder.java:313)
at com.google.zxing.qrcode.encoder.Encoder.recommendVersion (Encoder.java:213)
at com.google.zxing.qrcode.encoder.Encoder.encode (Encoder.java:147)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl. (QrCodeDrawable.kt:44)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableKt.QrCodeDrawable (QrCodeDrawable.kt:29)

Versions
Library : '1.6.2'
Android: '12'

Probably content is too big. Need a code snippet to reproduce

Got it, i will watch this error in other devices and let you know. I am generating Qr code with UTF-8 charset.

When data is big can you throw that exception so we can display message or do something when exception occurred . Right now app is crashing when data is too big.

QrCodeDrawableImpl(
    data: QrData,
    private val options: QrVectorOptions,
    charset: Charset?=null
) : Drawable() {

    private var anchorCenters: List<Pair<Int, Int>>

    private val initialMatrix: QrCodeMatrix

    private val shapeIncrease : Int

    init {
           val code = Encoder.encode(                **<=== if you can throw writer exception or catch it if possible.**
            data.encode(),
            with(options.errorCorrectionLevel) {
                if (this == QrErrorCorrectionLevel.Auto)
                    fit(options.logo, options.codeShape).lvl
                else lvl
            },
            charset?.let {
                mapOf(EncodeHintType.CHARACTER_SET to it)
            })

Caused by com.google.zxing.WriterException:
at com.google.zxing.qrcode.encoder.Encoder.chooseVersion (Encoder.java:313)
at com.google.zxing.qrcode.encoder.Encoder.recommendVersion (Encoder.java:213)
at com.google.zxing.qrcode.encoder.Encoder.encode (Encoder.java:147)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl. (QrCodeDrawable.kt:44)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableKt.QrCodeDrawable (QrCodeDrawable.kt:29)

There is an exception already. Why do i need to throw another one.

You can catch this exception and display anything you want

Yeah but its unchecked so writing try catch with WriterException gives error any way i will do with base exception class thanks for your time.