'Why am getting an error when trying to print a specific JPanel in NetBeans?

First, I'm trying to add a JPG to a JPanel, generate an ID from the database, then print it; however, I'm getting an error when I click on the "print" button. Previously, it was working but now it doesn't.

Could someone help me out? Thank you.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "sun.print.Win32PrintService.findPaperID(javax.print.attribute.standard.MediaSizeName)" because "this.myService" is null

Here is the code that breaks when I call jButton6ActionPerformed:

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  Toolkit tkp = jPanel3.getToolkit();
  PrintJob pjp = tkp.getPrintJob(this, null, null);
  Graphics g = pjp.getGraphics();
  jPanel3.print(g);
  g.dispose();
  pjp.end();
}  


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source