ObservableList和TableView上的NullPointerException setItems

时间:2017-02-16 05:54:25

标签: java rest javafx-2

我的FXML控制器

public class CustomerFXMLController implements Initializable 

有以下defs

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

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);
        }
    }

当我想要复制我用jersey检索的customerList时,我得到一个NullPointerException(它在该阶段有数组和内容正确)

customersTable.setItems(customerList);

我对Java的了解还不足以弄清楚为什么setItems不起作用!
请帮助

1 个答案:

答案 0 :(得分:0)

由于def double_hashing(keys, hashtable_size, double_hash_value): hashtable_list = [None] * hashtable_size for i in range(len(keys)): hashkey = keys[i] % hashtable_size if hashtable_list[hashkey] is None: hashtable_list[hashkey] = keys[i] else: new_hashkey = hashkey while hashtable_list[new_hashkey] is not None: steps = double_hash_value - (keys[i] % double_hash_value) new_hashkey = (new_hashkey + steps) % hashtable_size ## problem 1 is here hashtable_list[new_hashkey] = keys[i] return hashtable_list ## problem 2 is here values = [26, 54, 94, 17, 31, 77, 44, 51] print( double_hashing(values, 13, 5) ) [26, None, 54, 94, 17, 31, 44, 51, None, None, None, None, 77] null的有效值,我认为customerListcustomersTable

如果您从构造函数中调用null,则retrieveAllCustomers将为customersTable。从null调用它,在构造和设置所有initialize()元素之后运行。