title: Java applet class can't be instantiated
body: <p>I am new to java and I'm having trouble getting my applet to run. For some reason the class can't be instantiated. I have tried a few things but nothing has helped, I'm really stuck.</p>
  
  <p>Here is the error I'm receiving.</p>
  
  <pre><code>load: com.yunatech.pns.chequeprint.HTMLPrinter.class can't be instantiated.
  java.lang.InstantiationException: com.yunatech.pns.chequeprint.HTMLPrinter
  at java.lang.Class.newInstance0(Unknown Source)
  at java.lang.Class.newInstance(Unknown Source)
  at sun.applet.AppletPanel.createApplet(Unknown Source)
  at sun.applet.AppletPanel.runLoader(Unknown Source)
  at sun.applet.AppletPanel.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Here is my code.</p>
  
  <pre><code>package com.yunatech.pns.chequeprint;
  
  import java.applet.Applet;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.print.Book;
  import java.awt.print.PageFormat;
  import java.awt.print.Paper;
  import java.awt.print.Printable;
  import java.awt.print.PrinterException;
  import java.awt.print.PrinterJob;
  import java.io.IOException;
  
  import javax.swing.JEditorPane;
  import javax.swing.JFrame;
  
  public class HTMLPrinter extends Applet implements Printable{
      /**
       * 
       */
      private static final long serialVersionUID = 2343838467856002371L;
      private final JEditorPane printPane;
  
      public HTMLPrinter(JEditorPane editorPane){
          printPane = editorPane;
      }
  
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex){
          if (pageIndex &gt;= 1) return Printable.NO_SUCH_PAGE;
  
          Graphics2D g2d = (Graphics2D)graphics;
          g2d.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY());
  
          printPane.setSize((int)pageFormat.getImageableWidth(), (int)pageFormat.getImageableHeight());
          printPane.print(g2d);
  
          return Printable.PAGE_EXISTS;
      }
  
      protected static String dump(Paper paper) {
          StringBuilder sb = new StringBuilder(64);
          sb.append(paper.getWidth()).append("x").append(paper.getHeight())
                  .append("/").append(paper.getImageableX()).append("x").
                  append(paper.getImageableY()).append(" - ").append(paper
                  .getImageableWidth()).append("x").append(paper.getImageableHeight());
          return sb.toString();
      }
  
      protected static String dump(PageFormat pf) {
          Paper paper = pf.getPaper();
          return dump(paper);
      }
  
      public void main(String[] args){
  
          final JFrame frame = new JFrame("Letter wrap test"); 
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  
          final JEditorPane htmlTextPane = new JEditorPane(); 
  
          String paramUrl   = getParameter("paramUrl");
  
          htmlTextPane.setContentType("text/html");
          try {
              htmlTextPane.setPage(paramUrl);
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
  
          HTMLPrinter target = new HTMLPrinter(htmlTextPane);
  
          PrinterJob pj = PrinterJob.getPrinterJob();
          if (pj.printDialog()) {
              PageFormat pf = pj.defaultPage();
              Paper paper = pf.getPaper();
              double width = 8d * 72d;
              double height = 4d * 72d;
              double margin = 0.1d * 72d;
              paper.setSize(width, height);
              paper.setImageableArea(
                      margin,
                      0,
                      width - (margin * 2),
                      height);
              System.out.println("Before- " + dump(paper));
              pf.setOrientation(PageFormat.PORTRAIT);
              pf.setPaper(paper);
              System.out.println("After- " + dump(paper));
              System.out.println("After- " + dump(pf));
              dump(pf);
              PageFormat validatePage = pj.validatePage(pf);
              System.out.println("Valid- " + dump(validatePage));
  
              Book pBook = new Book();
              pBook.append(target, pf);
              pj.setPageable(pBook);
  
              try {
                  pj.print();
              } catch (PrinterException ex) {
                  ex.printStackTrace();
              }
          }
  
      } //main
  
  }
  </code></pre>
  
  <p>If anyone could help point me in the right direction I'd be very grateful.</p>
  
  <p>Thanks.</p>