Skip to content

App crashes when QR code is opened #1

Closed

Description

@Adithr123

[REDACTED PERSONAL INFORMATION]

The intended behavior is that the QR code opens.

What actually happens: The app crashes

I'm on a Pixel 9a with Android version 17.

Activity

  1. sameerasw commented on Aug 28, 2026

    @sameerasw
    Owner

    Ohhh that is interesting... I think there might be some data being problematic... I might need some better parsing for the QR... Will look into that

  2. self-assigned this
    on Aug 28, 2026
  3. Adithr123 commented on Aug 28, 2026

    @Adithr123
    Author

    I just noticed that the video I had attached failed to upload. My bad! I sent both the video and a bug report dump to your email! Hope that helps!

  4. sameerasw commented on Aug 28, 2026

    @sameerasw
    Owner

    I just noticed that the video I had attached failed to upload. My bad! I sent both the video and a bug report dump to your email! Hope that helps!

    Ohh no no it was uploaded, I deleted it because it had some personal info of yours... I guess it's something I'm gonna have to deal with a lot in this project 😁

  5. Adithr123 commented on Aug 28, 2026

    @Adithr123
    Author

    I just noticed that the video I had attached failed to upload. My bad! I sent both the video and a bug report dump to your email! Hope that helps!

    Ohh no no it was uploaded, I deleted it because it had some personal info of yours... I guess it's something I'm gonna have to deal with a lot in this project 😁

    Oh, sorry! It's all public info, though, and most if not all of that info is attached to my git profile lol

  6. mariohdel14nasa-lang commented on Aug 29, 2026

    @mariohdel14nasa-lang

    Just found the same bug on my Galaxy A17 running Android 16. Although I cannot seem to replicate it on a Galaxy S24 running Android 16. Looks lite a issue linked to RAM or CPU.

  7. sameerasw commented on Aug 31, 2026

    @sameerasw
    Owner

    Found it, Finally play console reported the crash logs

    Exception cb2:
      at com.google.zxing.WriterException.<init> (WriterException.java:31)
      at com.google.zxing.qrcode.encoder.Encoder.chooseVersion (Encoder.java:320)
      at com.google.zxing.qrcode.encoder.Encoder.recommendVersion (Encoder.java:218)
      at com.google.zxing.qrcode.encoder.Encoder.encode (Encoder.java:152)
      at com.google.zxing.qrcode.QRCodeWriter.encode (QRCodeWriter.java:78)
      at com.sameerasw.medrop.utils.QrCodeGenerator.generateQrBitmap (QrCodeGenerator.java:34)
      at com.sameerasw.medrop.ui.sheets.MeDropBottomSheetKt$MeDropBottomSheet$8$1$1.invokeSuspend (MeDropBottomSheet.kt:261)
      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
      at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:101)
      at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.java:113)
      at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:89)
      at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.java:589)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:823)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:720)
      at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:707)
    

    Summary

    The application crashed due to an unhandled com.google.zxing.WriterException during the QR code generation process. This exception was thrown by the ZXing library’s Encoder.chooseVersion method, which is called internally when trying to determine the appropriate size (version) of the QR code for the provided data. This failure typically occurs when the input string contains too much data to fit within the maximum allowed capacity of a standard QR code, or when the combination of data size and the requested Error Correction Level (ECL) exceeds the capacity limits of the library. The crash occurred asynchronously within a Kotlin coroutine triggered from the MeDropBottomSheet UI component.

    Potential Solutions

    1. Implement Exception Handling in the QR Generator
      A try-catch block should be implemented around the QRCodeWriter.encode call inside the QrCodeGenerator.generateQrBitmap method. Since WriterException is a checked exception, failing to catch it causes the application to crash when the QR code generation fails. By catching this exception, the method can return null or a fallback image, allowing the UI to handle the failure gracefully instead of terminating the app. The calling coroutine in MeDropBottomSheet.kt can then check for a null result and display an appropriate error message to the user.
    public Bitmap generateQrBitmap(String content, int width, int height) {
        try {
            QRCodeWriter writer = new QRCodeWriter();
            BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height);
            // Code to convert bitMatrix to Bitmap...
            return bitmap;
        } catch (WriterException e) {
            // Log the exception and return null to prevent a crash
            return null;
        }
    }
    
    1. Optimize the Error Correction Level
      The error correction level of the QR code should be explicitly configured to a lower setting, such as ErrorCorrectionLevel.L (Low) or ErrorCorrectionLevel.M (Medium). High error correction levels (like ErrorCorrectionLevel.H) consume a significant portion of the QR code's capacity for recovery data, leaving less space for the actual payload and triggering the chooseVersion exception. By reducing the error correction level, more data can be packed into the QR code before the maximum version limit is exceeded. This configuration is passed to the QRCodeWriter.encode method using an encoding hints map.
    import com.google.zxing.EncodeHintType;
    import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
    import java.util.HashMap;
    import java.util.Map;
    
    // Inside generateQrBitmap:
    Map<EncodeHintType, Object> hints = new HashMap<>();
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
    BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
    
    1. Validate and Truncate Input Data
      Input validation must be performed on the text string before it is passed to the QR code generator. The maximum capacity of a QR code is strictly limited, and if the input data is dynamically generated (such as long URLs or large payloads) and exceeds this limit, the encoder will fail. Validating the length of the string beforehand ensures that unsafe data is rejected or truncated prior to attempting the encoding process.
    public Bitmap generateQrBitmap(String content, int width, int height) {
        // Standard limit for alphanumeric QR codes with low error correction is 4,296 characters
        if (content == null || content.trim().isEmpty() || content.length() > 2953) {
            return null;
        }
        // Proceed with encoding...
    }
    
  8. pinned this issue on Aug 31, 2026
  9. mariohdel14nasa-lang commented on Aug 31, 2026

    @mariohdel14nasa-lang

    Just tried the first one. It doesn't work but the implementation is very rough so I don't know

    Image Image
  10. mariohdel14nasa-lang commented on Aug 31, 2026

    @mariohdel14nasa-lang

    Just fixed it! (With a little vibecoding tho) https://github.com/mariohdel14nasa-lang/Essential-Tap

  11. added a commit that references this issue on Sep 1, 2026
    c12b4b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions