Java 为什么我在使用org.activiti.bpmn.BpmnAutoLayout为我的bpmn文件生成DI信息时会得到NullPointerException?

Java 为什么我在使用org.activiti.bpmn.BpmnAutoLayout为我的bpmn文件生成DI信息时会得到NullPointerException?,java,xml,activiti,bpmn,Java,Xml,Activiti,Bpmn,我可以问您一个关于在maven dependency activiti bpmn布局中使用BpmnAutoLayout类的问题吗 我使用activiti bpmn模型api以编程方式创建了一个XML格式的.bpmn文件,其中没有DI信息bpmnWithoutDI.bpmn。我想使用BpmnAutoLayout类为我的bpmnWithoutDI.BPMNXML文件自动生成DI信息。但当我运行我的程序时,我得到以下异常: 谁能告诉我怎么解决这个问题吗 您可以从以下URL下载我的源代码: 它是Ecli

我可以问您一个关于在maven dependency activiti bpmn布局中使用BpmnAutoLayout类的问题吗

我使用activiti bpmn模型api以编程方式创建了一个XML格式的.bpmn文件,其中没有DI信息bpmnWithoutDI.bpmn。我想使用BpmnAutoLayout类为我的bpmnWithoutDI.BPMNXML文件自动生成DI信息。但当我运行我的程序时,我得到以下异常:

谁能告诉我怎么解决这个问题吗

您可以从以下URL下载我的源代码:

它是EclipseMaven项目的zip文件,包含我的java源代码和输入文件bpmnWithoutDI.bpmn。您只需导入maven项目并运行AutoLayoutDemo.java即可重现异常

我还包括以下代码:

AutoLayoutDemo.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;


public class AutoLayoutDemo {

    private BpmnModel convertXmlFileWithoutDIToBpmnModel(String fileName) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
        InputStream xmlStream = new FileInputStream(new File(fileName));
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(in);
        return new BpmnXMLConverter().convertToBpmnModel(xtr);
    }

    private void autoLayoutBpmnModel(BpmnModel model) {
        BpmnAutoLayout autoLayout = new BpmnAutoLayout(model);
        autoLayout.execute();
    }

    private void generateXmlFileWithDI(BpmnModel model, String fileName) {
        File file = new File(fileName);



        try (FileOutputStream fos = new FileOutputStream(file)) {

            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] byteArray = new BpmnXMLConverter().convertToXML(model);
            fos.write(byteArray);
            fos.flush();
            fos.close();

            System.out.println("Done");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
        AutoLayoutDemo demo = new AutoLayoutDemo();
        BpmnModel model = demo.convertXmlFileWithoutDIToBpmnModel("bpmnWithoutDI.bpmn");
        demo.autoLayoutBpmnModel(model);
        demo.generateXmlFileWithDI(model, "bpmnWithDI.bpmn");
    }

}
bpmnWithoutDI.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process_dispute_extractor" name="dispute_extractor" isExecutable="true">
    <subProcess id="process_dispute_extractor-extract_urls" name="STEP extract_urls: This step opens the AVC portal and gathers all the unresolved chargeback urls">
      <startEvent id="process_dispute_extractor-extract_urls-start" name="start"></startEvent>
      <endEvent id="process_dispute_extractor-extract_urls-end" name="end"></endEvent>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-0"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-1" name="get the chargeback id">
        <startEvent id="process_dispute_extractor-extract_urls-1-0" name="Start"></startEvent>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-1"></exclusiveGateway>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-2"></exclusiveGateway>
        <serviceTask id="process_dispute_extractor-extract_urls-1-3" name="add to the list of urls to process" activiti:delegateExpression="process_dispute_extractor-extract_urls-1-3implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-1-4" name="End"></endEvent>
      </subProcess>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-2"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-3" name="Send 150 urls to image analyzer process module">
        <startEvent id="process_dispute_extractor-extract_urls-3-0" name="Start"></startEvent>
        <serviceTask id="process_dispute_extractor-extract_urls-3-1" name="JUMP TO image_analyzer" activiti:delegateExpression="process_dispute_extractor-extract_urls-3-1implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-3-2" name="End"></endEvent>
      </subProcess>
    </subProcess>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-2" name="Else" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-3" name="If the id hasn't been processed" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-3"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-3--process_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-3" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-0--process_dispute_extractor-extract_urls-1-1" sourceRef="process_dispute_extractor-extract_urls-1-0" targetRef="process_dispute_extractor-extract_urls-1-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-2--process_dispute_extractor-extract_urls-1-4" sourceRef="process_dispute_extractor-extract_urls-1-2" targetRef="process_dispute_extractor-extract_urls-1-4"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-1" name="For each url" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-1" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3-0--process_dispute_extractor-extract_urls-3-1" sourceRef="process_dispute_extractor-extract_urls-3-0" targetRef="process_dispute_extractor-extract_urls-3-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3-1--process_dispute_extractor-extract_urls-3-2" sourceRef="process_dispute_extractor-extract_urls-3-1" targetRef="process_dispute_extractor-extract_urls-3-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-3" name="For each time" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-3"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3--process_dispute_extractor-extract_urls-2" sourceRef="process_dispute_extractor-extract_urls-3" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-2" name="Loop over" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-start--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-start" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-end" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-end"></sequenceFlow>
    <startEvent id="process_dispute_extractor-start" name="Start"></startEvent>
    <endEvent id="process_dispute_extractor-end" name="End"></endEvent>
    <sequenceFlow id="process_dispute_extractor-start--process_dispute_extractor-extract_urls" sourceRef="process_dispute_extractor-start" targetRef="process_dispute_extractor-extract_urls"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls--process_dispute_extractor-end" sourceRef="process_dispute_extractor-extract_urls" targetRef="process_dispute_extractor-end"></sequenceFlow>
  </process>
</definitions>

谢谢大家!

我知道你的代码,一切正常。 问题是您的bpmn文件

我创建了一个新的bpmn文件bpmnWithoutDI2,包含xml内容:

    <?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>
一切正常,运行代码bpmnWithDI.bpmn后生成。
但我认为问题出在sequenceFlow元素中的某个地方,因为没有它们,代码就可以成功运行。

下面是正确的bpmn文件,我已经更改并测试了它,我希望这可以帮助您

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process_dispute_extractor" name="dispute_extractor" isExecutable="true">
    <subProcess id="process_dispute_extractor-extract_urls" name="STEP extract_urls: This step opens the AVC portal and gathers all the unresolved chargeback urls">
      <startEvent id="process_dispute_extractor-extract_urls-start" name="start"></startEvent>
      <endEvent id="process_dispute_extractor-extract_urls-end" name="end"></endEvent>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-0"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-1" name="get the chargeback id">
        <startEvent id="process_dispute_extractor-extract_urls-1-0" name="Start"></startEvent>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-1"></exclusiveGateway>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-2"></exclusiveGateway>
        <serviceTask id="process_dispute_extractor-extract_urls-1-3" name="add to the list of urls to process" activiti:delegateExpression="process_dispute_extractor-extract_urls-1-3implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-1-4" name="End"></endEvent>
        <sequenceFlow id="xprocess_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-3" name="If the id hasn't been processed" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-3"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-3--process_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-3" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>     
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-0--process_dispute_extractor-extract_urls-1-1" sourceRef="process_dispute_extractor-extract_urls-1-0" targetRef="process_dispute_extractor-extract_urls-1-1"></sequenceFlow>     
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-2--process_dispute_extractor-extract_urls-1-4" sourceRef="process_dispute_extractor-extract_urls-1-2" targetRef="process_dispute_extractor-extract_urls-1-4"></sequenceFlow>     
      </subProcess>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-2"></exclusiveGateway>
      <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-3" name="For each time" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-3"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-3--process_dispute_extractor-extract_urls-2" sourceRef="process_dispute_extractor-extract_urls-3" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-2" name="Loop over" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-start--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-start" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-end" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-end"></sequenceFlow>     
      <subProcess id="process_dispute_extractor-extract_urls-3" name="Send 150 urls to image analyzer process module">
        <startEvent id="process_dispute_extractor-extract_urls-3-0" name="Start"></startEvent>
        <serviceTask id="process_dispute_extractor-extract_urls-3-1" name="JUMP TO image_analyzer" activiti:delegateExpression="process_dispute_extractor-extract_urls-3-1implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-3-2" name="End"></endEvent>
        <sequenceFlow id="process_dispute_extractor-extract_urls-3-0--process_dispute_extractor-extract_urls-3-1" sourceRef="process_dispute_extractor-extract_urls-3-0" targetRef="process_dispute_extractor-extract_urls-3-1"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-3-1--process_dispute_extractor-extract_urls-3-2" sourceRef="process_dispute_extractor-extract_urls-3-1" targetRef="process_dispute_extractor-extract_urls-3-2"></sequenceFlow>
      </subProcess>
      <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-1" name="For each url" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-1"></sequenceFlow>       
      <sequenceFlow id="process_dispute_extractor-extract_urls-1--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-1" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    </subProcess>
    <startEvent id="process_dispute_extractor-start" name="Start"></startEvent>
    <endEvent id="process_dispute_extractor-end" name="End"></endEvent>
    <sequenceFlow id="process_dispute_extractor-start--process_dispute_extractor-extract_urls" sourceRef="process_dispute_extractor-start" targetRef="process_dispute_extractor-extract_urls"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls--process_dispute_extractor-end" sourceRef="process_dispute_extractor-extract_urls" targetRef="process_dispute_extractor-end"></sequenceFlow>

  </process>
</definitions>
BPMN导出的图像:


嗨,Mehdi,谢谢你的回答。你能告诉我更多关于我的原始bpmn文件中的错误吗?我以编程方式为要显示的进程生成bpmn文件。因此,我需要知道BPMN文件中的错误,并更正生成代码以显示流程。实际上,当我在EclipseBPMN2建模器中手动打开bpmn文件时,EclipseBPMN2建模器可以生成DI信息并为原始bpmn文件显示正确的图表。但我无法提取建模器生成DI信息的特定源代码。非常感谢。非常感谢。我也发现了问题所在。子流程中的for元素应该放在该子流程中现在我可以使用activiti bpm布局自动生成DI信息,但其输出的外观不太好。可能有轻微的重叠。实际上,EclipseBPMN2Modeler在布局和显示bpmn文件方面做得非常好,没有DI信息。它是开源的。但我无法提取源代码中自动生成DI信息的特定部分。我想提取该代码并生成一个函数,该函数在不使用DI的情况下读取bpmn文件,使用modeler中的代码生成DI,并输出一个带有DI的bpmn文件。你能帮我吗?如果你能帮我,我会非常感激的!!!