alexzhirkevich / custom-qr-generator

Android library for creating QR codes with logo, custom shapes, colors, background image. Powered by ZXing
MIT License
173 stars 18 forks source link

com.google.zxing.WriterException #32

Closed hardikbhalodi closed 10 months ago

hardikbhalodi commented 1 year ago

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'

alexzhirkevich commented 1 year ago

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

hardikbhalodi commented 1 year ago

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

hardikbhalodi commented 1 year ago

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)
            })
alexzhirkevich commented 1 year ago

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

hardikbhalodi commented 1 year ago

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.