Answer the question
In order to leave comments, you need to log in
Why are my strings null?
I wanted to display an image and text in a ListView. But I get an error java.lang.NullPointerException update item , and if I check that item is null, then everything works, but does not display the text.
this is the method where i create the object
public ObservableList addUser (){
// List<Contact> userList = new ArrayList<>();
ObservableList<Contact> userObservableList = FXCollections.observableArrayList();
userObservableList.addAll(new Contact(AVATAR,"Megan","Fox",NET_INDICATOR));
return userObservableList;
}
@Override
protected void updateItem(Contact contact, boolean empty) {
super.updateItem(contact, empty);
if ( empty||contact == null){
setText(null);
setGraphic(null);
}else {
if (mFXMLLoader == null) {
mFXMLLoader = new FXMLLoader(getClass().getClassLoader().getResource("fxml/contactList.fxml"));
mFXMLLoader.setController(this);
try {
mFXMLLoader.load();
} catch (IOException e) {
System.out.println(" не загрузил ");
}
Image avatar = new Image(contact.getAvatar());
avatarContactList.setImage(avatar);
/* TODO Если убрать проверку то вылетает исключение */
if (contact == null){
lblName.setText(contact.getName());
lblSense.setText(contact.getSense());
}
Image indicator = new Image(contact.getNetStatus());
netStatusContactList.setImage(indicator);
setText(null);
setGraphic(contactList);
}else {
System.out.println("Снова не получилось, LOADER != Null ");
}
}
}
Answer the question
In order to leave comments, you need to log in
if it crashes here:
if (contact == null){
lblName.setText(contact.getName());
lblSense.setText(contact.getSense());
}
if ( empty||contact == null){
setText(null);
setGraphic(null);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question