here are my classes
public class PersonView extends Composite{
private Person person;
@UiField
FirstnameView firstnameView;
@UiField
LastnameView lastnameView;
public PersonView(Person person) {
setData(person);
}
public void setData(Person person) {
firstnameView.setData(person.getFirstname());
lastnameView.setData(person.getLastname());
}
}
public class FirstnameView extends Composite{
private Firstname firstname;
@UiField
TextBox firstnameTextBox;
public FirstnameView() {
}
public void setData(Firstname firstname) {
firstnameTextBox.setValue(firstname.getFirstname());
}
}
public class LastnameView extends Composite{
private Lastname lastname;
@UiField
TextBox lastnameTextBox;
public LastnameView() {
}
public void setData(Lastname lastname) {
lastnameTextBox.setValue(lastname.getLastname());
}
}
My problem is that when I call method setData(person)
, I get the following error
java.lang.NullPointerException: null in the line `firstnameView.setData(person.getFirstname())`
I think that @UiField FirstnameView firstnameView
(and the lastnameView
too) doesn't create an object. I really don't understand how gwt works in this case. Help me please resolve it and set data.
@UiField
s are only "injected" when you callinitAndBindUi
on aUiBinder
instance, passing an instance with the@UiField
s as argument.In other words, your
PersonView
constructor should begin with initializing aUiBinder
instance and callingbinder.initAndBindUi(this)
before you can callsetData()
.