Unreported exception

1 resposta
L

Pessoal vejam o codigo, o erro que me dá é o seguinte : unreported exception java.awt.print.PrinterException; must be caught or declared to be thrown.
O que devo fazer para resolver isso e imprimir a minha tabela ?

try {
      
      Printable printable = table.getPrintable(JTable.PrintMode.FIT_WIDTH,
                                               new MessageFormat("My Table"),
                                               new MessageFormat("Page - {0}"));

      
      PrinterJob job = PrinterJob.getPrinterJob();

     
      job.setPrintable(printable);


      PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();

      // display a print dialog and record whether or not the user cancels it
      boolean printAccepted = job.printDialog(attr);

      // if the user didn't cancel the dialog
      if (printAccepted) {
          // do the printing (may need to handle PrinterException)

job.print(attr); //ERRO : unreported exception java.awt.print.PrinterException; must be caught or declared to be thrown

}
  } finally {

  }

1 Resposta

E

ola boa noite

bom pelo que vi no seu codigo tu abre o bloco try e segundo me
lembre para todo try você deve ter um catch para tratar
da exception

antes do bloco finally, insira o catch( Exception e ) {}
e teste novamente provavelmente pare o erro :wink:

abraços

Criado 1 de maio de 2006
Ultima resposta 1 de mai. de 2006
Respostas 1
Participantes 2