带有qrgen和zxing库的异常java.lang.NoSuchMethodError [英] Exception java.lang.NoSuchMethodError with qrgen and zxing libraries

查看:712
本文介绍了带有qrgen和zxing库的异常java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我在我的项目中使用maven,但由于一些迁移问题,我必须(暂时)下载jar。

Normally, I use maven in my project but because of some migration problems I have to (temporally) download jars.

我想使用以下代码:

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;

public class Main {
    public static void main(String[] args) {
        ByteArrayOutputStream out = QRCode.from("Hello World")
                                        .to(ImageType.PNG).stream();

        try {
            FileOutputStream fout = new FileOutputStream(new File(
                    "C:\\QR_Code.JPG"));

            fout.write(out.toByteArray());

            fout.flush();
            fout.close();

        } catch (FileNotFoundException e) {
            // Do Logging
        } catch (IOException e) {
            // Do Logging
        }
    }
}

我在项目中添加了一个jar:

I added one jar to my project:

qrgen-1.3.jar



<然后,我有一个例外:

but then, I had got an exception:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/zxing/Writer

所以我添加了另外两个罐子:

so I added two other jars:

zxing-core-1.7.jar
zxing-j2se-1.7.jar

现在,我又遇到了另一个错误:

and now, I have got another error:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.zxing.Writer.encode(Ljava/lang/String;Lcom/google/zxing/BarcodeFormat;IILjava/util/Map;)Lcom/google/zxing/common/BitMatrix;

这里我无法修复它。

哪里可能有问题?

我确信它来自我的代码的第一行:

I am sure it goes from first line fo my code:

ByteArrayOutputStream out = QRCode.from("Hello World").to(ImageType.PNG).stream();


推荐答案

嗯,你使用的是这个库的版本错误zxing。看起来像1.3使用2.0,你将它与1.7配对: https:/ /github.com/kenglxn/QRGen/blob/e74f7912e19eb99c84100d5840e2be2e48108747/pom.xml#L40

Well, you are using this library with the wrong version of zxing. Looks like 1.3 uses 2.0, and you are pairing it with 1.7: https://github.com/kenglxn/QRGen/blob/e74f7912e19eb99c84100d5840e2be2e48108747/pom.xml#L40

这几乎总是这些错误的含义。使用像Maven这样的工具可以避免这种情况。此外,这些依赖项的两个版本现在都已过时了。

This is almost always what these kinds of errors mean. Using a tool like Maven avoids this. Also, both versions of these dependencies are old now.

这篇关于带有qrgen和zxing库的异常java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆