Type mismatch: cannot convert from ByteMatrix to BitMatrix

前端 未结 3 464
孤城傲影
孤城傲影 2021-01-26 13:00

I am creating a QR code generator program in JAVA using ZXING library. The program is

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterExcept         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-26 13:34

    According to the javadoc here and the source code here, the QRCodeWriter.encode methods return a BitMatrix, not a ByteMatrix. So, that compilation error should not occur.

    Unless ....

    ... you are using some version1 of the com.google.zxing library that is incompatible with those javadocs. Check where you got your zxing JAR file from.

    Despite searching, I haven't been able to find the version with this incompatibility. However:

    1. I note that the official library has been forked many times on GitHub, and any one of those could be the source of the incompatibility.

    2. I found this which clearly a fork, and clearly has tweaked encode. However, the people who did this have at least had the good sense to change the package name!


    I don't know if this is relevant, but it appears that in the C# version of this API, the QRCodeWriter.encode method does return a ByteMatrix; see here for evidence. Maybe you've stumbled across someone's misguided attempt to "fix" the Java API to match the C# API.

提交回复
热议问题