I'm trying to set the printService for a printerJob but keep getting a null pointer excpetion and I can see what the error is...
Here is the constuctor which does the setup...
When its called I get the following output:
Win32 Printer : \\Heather\HP DeskJet 1120C 0
Win32 Printer : Microsoft Office Document Image Writer 1
Win32 Printer : HP LaserJet 4100 PCL 6 2
Win32 Printer : hp LaserJet 1300 PCL 6 3
Win32 Printer : Acrobat PDFWriter 4
trying to use Win32 Printer : hp LaserJet 1300 PCL 6
java.lang.NullPointerException
at printUtils.DocumentRenderer.<init>(DocumentRenderer.java:85)
at printagain.main(printagain.java:29)
Exception in thread "main"
Any ideas?
Here is the constuctor which does the setup...
Code:
public DocumentRenderer() {
pFormat = new PageFormat();
//pJob = PrinterJob.getPrinterJob();
PrintService service[] = PrinterJob.lookupPrintServices();
for (int i = 0; i < service.length; i++) {
System.out.println("\t" +service[i] + " " + i);
}
try {
PrintService pserv = service[3];
System.out.println("trying to use " + pserv);
pJob.setPrintService(pserv);
} catch (PrinterException pe) {
System.out.println(pe.getMessage());
}
}
When its called I get the following output:
Win32 Printer : \\Heather\HP DeskJet 1120C 0
Win32 Printer : Microsoft Office Document Image Writer 1
Win32 Printer : HP LaserJet 4100 PCL 6 2
Win32 Printer : hp LaserJet 1300 PCL 6 3
Win32 Printer : Acrobat PDFWriter 4
trying to use Win32 Printer : hp LaserJet 1300 PCL 6
java.lang.NullPointerException
at printUtils.DocumentRenderer.<init>(DocumentRenderer.java:85)
at printagain.main(printagain.java:29)
Exception in thread "main"
Any ideas?