你能告诉我为什么我在这里得到ClassCastException
异常吗?
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具有属性“vorname”(德语为名字),它是带有 getter 和 setter 的私有字段。
private String vorname;
public Apprentice(){
;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}