Quantcast

NullPointerException setItems on ObservableList and TableView

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

NullPointerException setItems on ObservableList and TableView

Morons
my FXML controller
Code:
public class CustomerFXMLController implements Initializable


has the following defs

Code:
@FXML   private TableView<CustomerTableModel> customersTable;
private ObservableList<CustomerTableModel> customerList = FXCollections.observableArrayList();




Code:
private void retrieveAllCustomers() {
        try {
            customerList = FXCollections.observableArrayList(CustomersJerseyClient.findAllCustomers());
            customersTable.setItems(customerList);
        } catch (NullPointerException e) {
            DialogUtil.buildExceptionDialog("An error has occurred", "customersTable seems empty", e).showAndWait();
            System.exit(-1);
        } catch (RuntimeException e) {
            DialogUtil.buildExceptionDialog("An error has occurred", "Failed to connect to web service", e).showAndWait();
            System.exit(-1);
        }
    }



I get a NullPointerException when I want to copy the customerList that I retrieved with jersey (it has the array and content is correct at that stage) in this line

Code:
customersTable.setItems(customerList);



My knowledge of Java is not enough to figure out why the setItems does not work!  
Any Help please
 [Embarassed]




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NullPointerException setItems on ObservableList and TableView

markwade
Just a guess; you say customerList "has the array and content is correct
at that stage" if so, customersTable probably hasn't been initialized
yet and is null.

Put a breakpoint at "customerList = FXCollections...", step over once
and examine customerList and customersTable (before
customersTable.setItems(customerList) is executed.

Also when you catch NullPointerException you might use
"e.printStackTrace()" for more information.


On 02/15/2017 06:48 AM, Morons wrote:

> my FXML controller
> Code:
> public class CustomerFXMLController implements Initializable
>
>
> has the following defs
>
> Code:
> @FXML   private TableView<CustomerTableModel> customersTable;
> private ObservableList<CustomerTableModel> customerList = FXCollections.observableArrayList();
>
>
>
>
> Code:
> private void retrieveAllCustomers() {
>          try {
>              customerList = FXCollections.observableArrayList(CustomersJerseyClient.findAllCustomers());
>              customersTable.setItems(customerList);
>          } catch (NullPointerException e) {
>              DialogUtil.buildExceptionDialog("An error has occurred", "customersTable seems empty", e).showAndWait();
>              System.exit(-1);
>          } catch (RuntimeException e) {
>              DialogUtil.buildExceptionDialog("An error has occurred", "Failed to connect to web service", e).showAndWait();
>              System.exit(-1);
>          }
>      }
>
>
>
> I get a NullPointerException when I want to copy the customerList that I retrieved with jersey (it has the array and content is correct at that stage) in this line
>
> Code:
> customersTable.setItems(customerList);
>
>
>
> My knowledge of Java is not enough to figure out why the setItems does not work!
> Any Help please
>   [Embarassed]
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

NullPointerException setItems on ObservableList and TableView

Morons
In reply to this post by Morons
I found a Spelling mistake in my FXML file :(  [Embarassed]

Embarassed I spelled customerTable instead of customersTable therfore you are indeed correct the FXML did not initialize the variable.




Loading...