调用 pack() JPOS 时获取 NullPointerException

Get NullPointerException when call pack() JPOS

我在 ISO 8583 工作。我使用 JPOS 来解析和反解析 ISO 消息。 但是,当我解析消息时,出现以下错误:

java.lang.NullPointerException
    at org.jpos.iso.ISOBasePackager.pack(ISOBasePackager.java:94)
    at org.jpos.iso.ISOMsg.pack(ISOMsg.java:442)
    at com.sti.payment.postpaid.service.TransactionService.response(TransactionService.java:76)
    at com.sti.payment.postpaid.App.main(App.java:35)

错误指向:

byte [] bIsoMsg = isoMsg.pack();

这是我的代码:

public void response(String responseMessage) throws Exception {
    // TODO Auto-generated method stub
    GenericPackager packager = new GenericPackager("de-payment-request.xml");

    // Buat ISO Messagenya
    ISOMsg isoMsg = new ISOMsg();
    isoMsg.setPackager(packager);
    isoMsg.setMTI("0210");
    isoMsg.set(1, "723A40010A818000");
    isoMsg.set(2, "162333444455556666");
    isoMsg.set(3, "380099");

    byte [] bIsoMsg = isoMsg.pack();
}

这是我的XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE isopackager SYSTEM "genericpackager.dtd">
<isopackager>
  <isofield
    id="1"
    length="64"
    name="BIT MAP"
    class="org.jpos.iso.IFA_BITMAP"
  />
  <isofield
    id="2"
    length="16"
    name="PRIMARY ACCOUNT NUMBER"
    class="org.jpos.iso.IFA_LLNUM"
  />
  <isofield
    id="3"
    length="6"
    name="PROCESSING CODE"
    class="org.jpos.iso.IFA_NUMERIC"
  />
</isopackager>

我错过了什么? 非常感谢。

位图字段(数据元素 1)由 jPOS 自动处理,因此您不必调用:

isoMsg.set(1, "723A40010A818000");

当您设置字段 1 时,jPOS 认为有些字段实际上未配置,这就是您获得 NPE 的原因,很可能 here(取决于您的版本)。

Answer

For now may be it is not the best and fit answer for my problem. Just exclude the ID 1 in your pack method. It works for me. Cause JPOS automatically add ID 1 and 2 for your message.