如何解决取消引用空指针的问题


byte bytes [] = Base64.getDecoder().decode(element.getElementsByTagName("Bytes").item(0).getTextContent());
Importer imp = null;
fmd = imp.ImportFmd(bytes, Fmd.Format.ANSI_378_2004, Fmd.Format.ANSI_378_2004);

我收到取消引用空指针的警告,如何在 ImportFmd 方法中解决此警告?我正在使用数字角色 SDK。

您需要一个 Importer 类的实例来调用 ImportFmd 方法。

一些谷歌搜索显示你可以通过这种方式获得一个Importer实例:

UareUGlobal.GetImporter()

因此,您的代码变为:

byte bytes [] = Base64.getDecoder().decode(element.getElementsByTagName("Bytes").item(0).getTextContent());
Importer imp = UareUGlobal.GetImporter();
fmd = imp.ImportFmd(bytes, Fmd.Format.ANSI_378_2004, Fmd.Format.ANSI_378_2004);
当你

第一次访问变量imp时,它是空的:在第二行中,你给它赋值null,在第三行,你调用方法ImportFmd它。

您需要查看Importer文档,了解如何正确设置它。它可以像

Importer imp = new Importer();

但是OTOH,它可能需要更多的工作来设置它。这里重要的是您必须为 imp 变量分配一个有效值,否则当您第一次访问它时它是 null,这将导致NullPointerException

最新更新