问题描述
我有一个使用护照阅读器扫描文档的项目,正确的使用方法是在开始使用之前初始化设备。事实是当我运行我的项目来测试它时(我在 Win10 上使用 Intellij),它工作得很好,没有问题,但是当我构建一个 jar 来导出它(包括护照阅读器库)时,会显示下一条消息:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "<local2>" is null
at Pr22.DocumentReaderDevice.init(UnkNown Source)
at Pr22.DocumentReaderDevice.<init>(UnkNown Source)
at Testing.PassportReaderOpen.main(PassportReaderOpen.java:15)
我在我的类 PassportReader.java 中第一次使用库对象 (Pr22.jar) 时,我查看了该方法是异常点和崩溃,但我找不到关于“local2”字符串的任何信息.
为了让您了解上下文,这是 PassportReader 类:
package Testing;
import Pr22.DocScanner;
import Pr22.DocumentReaderDevice;
import PrIns.Exceptions.General;
public class PassportReaderOpen {
static DocumentReaderDevice documentReader = null;
static DocScanner scanner;
public static void main(String[] args) {
try {
System.out.println("opening device");
documentReader = new DocumentReaderDevice();
documentReader.useDevice(0);
scanner = documentReader.getScanner();
System.out.println("The device " + documentReader.getDeviceName() + " is opened.");
documentReader.close();
System.out.println("Device closed");
} catch (General general) {
general.printstacktrace();
}
}
}
如您所见,崩溃发生在声明对象之后,因此库 Pr22 应该包含在构建的 jar 中,对吗?