0

As newbie in java i wanted to exercise a bit with itext. So far i was able to save my document as pdf with data using a javafx form. I created a table inside my form using a list. But when i wanted to create a table with an observablelist in itext i'm stuck. Can someone help me out and explain why it does work?

In the fxmlDocumentController i declared the following ObservableList.

  final ObservableList<ServiceDTO> listServices = FXCollections.observableArrayList();

then i create a actionEvent where i can see that listservices contains some stuff.

@FXML
private void handleButtonCreateInvoice(ActionEvent event) {

    InvoicePrint invoice = new InvoicePrint(listServices);
    invoice.CreateInvoicePDF();

}

But when it reached my class InvoicePrint it says error cannot access instance variable from static context. So here i'm stuck. Can someone explain me why it doesn't work ?

public InvoicePrint(ObservableList listServices) {      
    setListServices(listServices);       
}

then i want to pass the observablelist to a methode and get all the services data and store it into a table using itext. But it gives me the following error : non-static variable listServices cannot be referenced from a static context.

   for (ServiceDTO service : listServices) {

        table.addCell(service.getDefinition());
        table.addCell(service.getPriceExclVat().toString());
        table.addCell(service.getVat().toString());
        table.addCell(service.getPriceInclVat().toString());

   } 
mkl
  • 90,588
  • 15
  • 125
  • 265
Greg
  • 1,690
  • 4
  • 26
  • 52
  • 2
    The error is telling you what the issue is. `listServices` is a non-static (instance) variable, but you are trying to use it from a static method (`main` perhaps?). You need an _instance_ of the class where `listServices` is defined in order to use the `listServices` variable. – GriffeyDog Mar 19 '15 at 15:45
  • 1
    @GriffeyDog is right. This is not an iText question. It's a very basic Java question. – Bruno Lowagie Mar 19 '15 at 16:19

0 Answers0