Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: net.sourceforge.barbecue.linear.code128.Code128Barcode cannot be cast to java.awt.print.Printable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is this a bug related to Java 6? or to Barbacue? or an error in my code \(which I repeat, is just exactly the same to the code mentioned above. But nevertheless I post it below
The code you are trying to run is from the latest Alpha, and you are probably trying to run it against what was at the time the current release. In the Alpha (which is the ONLY version I can currently download), Barcode IS a Printable, and this example compiles and runs.
However, it doesn't actually PRINT anything. The results is a completely blank sheet of paper.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi there,
When I try to print a barcode according to the example in:
http://barbecue.svn.sourceforge.net/viewvc/barbecue/trunk/barbecue/src/zip/examples/PrintingExample.java?view=markup
I'm get this error:
try {
Barcode b = (Barcode)BarcodeFactory.createCode128(tbl.getValueAt(tbl.convertRowIndexToModel(minSelectionIndex),Attributes.ID.ordinal()).toString());
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable((Printable)b);
if (job.printDialog())
job.print();
} catch (BarcodeException be) {
be.printStackTrace();
JOptionPane.showMessageDialog(null,be.getMessage(),
"Error generating Barcode",JOptionPane.ERROR_MESSAGE);
} catch (PrinterException pe) {
pe.printStackTrace();
JOptionPane.showMessageDialog(null,pe.getMessage(),
"Printing Error",JOptionPane.ERROR_MESSAGE);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why do you try to cast from Barcode to Printable?
Do you think it's compatible type?
I do not think so;
Because of this:
Wow, way to be helpful (and wrong), guys.
The code you are trying to run is from the latest Alpha, and you are probably trying to run it against what was at the time the current release. In the Alpha (which is the ONLY version I can currently download), Barcode IS a Printable, and this example compiles and runs.
However, it doesn't actually PRINT anything. The results is a completely blank sheet of paper.