简体   繁体   English

org.krysalis.barcode4j.BarcodeException:找不到条形码配置元素

[英]org.krysalis.barcode4j.BarcodeException: No barcode configuration element not found

I want to generate a barcode in svg from a barcode xml. 我想从条形码xml在svg中生成条形码。 I have followed this: http://barcode4j.sourceforge.net/2.1/barcode-xml.html 我遵循了这一点: http : //barcode4j.sourceforge.net/2.1/barcode-xml.html

The input should be a configuration object created out of an xml file. 输入应该是从xml文件创建的配置对象。 The "cfgFile"[barcode.xml] file is of the following format: “ cfgFile” [barcode.xml]文件的格式如下:

<bc:barcode xmlns:bc="http://barcode4j.krysalis.org/ns" orientation="0" message="123456789">
    <bc:code39>
            <bc:height>15mm</bc:height>
            <bc:module-width>0.19mm</bc:module-width>
            <bc:wide-factor>2.5</bc:wide-factor>
    </bc:code39>
</bc:barcode>

When I try to send this as input to Barcode 4j: 当我尝试将其作为输入发送到条形码4j时​​:

DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
File cfgFile = new File("barcode.xml");
Configuration cfgnew = builder.buildFromFile(cfgFile);
DocumentFragment frag = 
BarcodeUtil.getInstance().generateSVGBarcode(cfgnew, "123456789");

I get the following error: 我收到以下错误:

Caused by: org.krysalis.barcode4j.BarcodeException: No barcode configuration element not found
at org.krysalis.barcode4j.BarcodeUtil.createBarcodeGenerator(Unknown Source) ~[Barcode4J-2.1.jar:?]
at org.krysalis.barcode4j.BarcodeUtil.createBarcodeGenerator(Unknown Source) ~[Barcode4J-2.1.jar:?]
at org.krysalis.barcode4j.BarcodeUtil.generateSVGBarcode(Unknown Source) ~[Barcode4J-2.1.jar:?

When I print a logger for cfgnew, I get this: bc:barcode:::@file 当我为cfgnew打印记录器时,得到以下信息:bc:barcode ::: @@ file

I was calling the wrong function to generate the barcode in SVG. 我在调用错误的函数以在SVG中生成条形码。 Instead of BarcodeUtil.getInstance().generateSVGBarcode(cfgnew, "123456789"); 代替BarcodeUtil.getInstance()。generateSVGBarcode(cfgnew,“ 123456789”);

Use this: bargen.generateBarcode(canvas, msg); 使用这个:bargen.generateBarcode(canvas,msg);

where bargen is the instance for a particular barcode configuration. 其中bargen是特定条形码配置的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM