Generating 1D barcodes with android
Hey, There's a lot of pos开发者_Python百科ts 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.
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.
精彩评论