使用android生成一维条形码

发布于 2024-10-16 11:42:43 字数 2444 浏览 0 评论 0原文

嘿,这里有很多关于读取条形码的帖子,但我想从一串数字生成条形码,并在我的应用程序中向用户显示生成的条形码。 我看过一些库 iTextPdf 和 Barbecue,特别是我一直在尝试使用 iTextPdf

我想知道是否有人知道或可以提供一个简单的实现或提出更好的建议......

我想画出条形码直接到自定义视图,以便与其他控件一起以线性布局显示。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Barcode128 code128 = new Barcode128();
    code128.setCodeType(Barcode128.CODE128);
    code128.setCode("123456789");
    Image image128 = code128.createTemplateWithBarcode(barcodeview, null, null);
}

对于初学者来说,这个错误和应用程序实际上不会运行,但我不知道如何将其绘制到布局上。

这会出现以下错误

02-07 23:55:31.868: ERROR/AndroidRuntime(212): Uncaught handler: thread main exiting due to uncaught exception
02-07 23:55:31.878: ERROR/AndroidRuntime(212): java.lang.VerifyError: com.itextpdf.text.pdf.Barcode128
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.example.barcodetest.Main.onCreate(Main.java:17)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.os.Looper.loop(Looper.java:123)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.main(ActivityThread.java:4203)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invokeNative(Native Method)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invoke(Method.java:521)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at dalvik.system.NativeStart.main(Native Method)

感谢您的帮助。

Hey, There's a lot of posts on here about read barcodes but I want to generate barcodes from a string of numbers and display the generated barcode to the user in my application.
I've had a look at a few libraries iTextPdf and Barbecue, in particular I've been trying to work with iTextPdf

I wondered if anyone knows of or could provide a simple implementation or suggest something better....

I want to draw the barcode directly to a custom view for display in a linear layout with other controls.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Barcode128 code128 = new Barcode128();
    code128.setCodeType(Barcode128.CODE128);
    code128.setCode("123456789");
    Image image128 = code128.createTemplateWithBarcode(barcodeview, null, null);
}

For starters this errors and the app wont actually run, but I don't know how to draw this on to the layout.

This gives the following error

02-07 23:55:31.868: ERROR/AndroidRuntime(212): Uncaught handler: thread main exiting due to uncaught exception
02-07 23:55:31.878: ERROR/AndroidRuntime(212): java.lang.VerifyError: com.itextpdf.text.pdf.Barcode128
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.example.barcodetest.Main.onCreate(Main.java:17)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.os.Looper.loop(Looper.java:123)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.main(ActivityThread.java:4203)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invokeNative(Native Method)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invoke(Method.java:521)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-07 23:55:31.878: ERROR/AndroidRuntime(212):     at dalvik.system.NativeStart.main(Native Method)

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三月梨花 2024-10-23 11:42:43

根据您的堆栈跟踪,iTextPDF 与 Android 不兼容,至少需要重新编译,并且可能比这更实质性的更改。请记住,iTextPDF for Android 有一个单独的项目 - 我不知道这是否是你正在使用什么。

在主要搜索引擎上搜索会出现此产品

Based on your stack trace, iTextPDF is not compatible with Android without at least a recompile, and probably more substantial changes than that. Bear in mind that there is a separate project for iTextPDF for Android -- I do not know if that is what you were using.

A search on a major search engine turns up this product.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文