1
你能告訴我爲什麼我在這裏得到ClassCastException
異常嗎?ClassCastException Beansbinding Java
protected void initDataBindings() {
BeanProperty<Apprentice, String> apprenticeBeanProperty = BeanProperty.create("vorname");
ObjectProperty<JTextField> jTextFieldObjectProperty = ObjectProperty.create();
AutoBinding<Apprentice, String, JTextField, JTextField> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, apprentice, apprenticeBeanProperty, txtVorname, jTextFieldObjectProperty);
autoBinding.bind();
}
這是文本字段:
{
txtVorname = new JTextField();
//txtVorname.setPreferredSize(new Dimension(txtVorname.getPreferredSize().width + 160, txtVorname.getPreferredSize().height));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
rightPanel.add(txtVorname, gbc);
}
和Apprentice.java具有attributee 「vorname」(德語爲姓名),其是與getter和setter私有字段。
private String vorname;
public Apprentice(){
;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}