Ошибка: java.lang.nullPointerException: не может вызвать "java.util.list.ilterator ()", потому что "список" null
Основной класс:
try {
jaxbContext = JAXBContext.newInstance(Recipes.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Recipes rec = (Recipes) jaxbUnmarshaller.unmarshal(new StringReader(xml));
List list = rec.getRecipes();
for (Recipe re: list){
System.out.println(re.getId());
}
} catch (JAXBException e) {
e.printStackTrace();
}
< /code>
Класс рецептов: < /p>
@XmlRootElement(name = "results")
public class Recipe {
private int id;
private String title;
private Image image;
public Recipe(){}
public Recipe(int id, String title, Image image){
this.id = id;
this.title = title;
this.image = image;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
< /code>
Рецепты класс: < /p>
@XmlRootElement
public class Recipes {
private List recipes;
public Recipes(){}
public Recipes(List recipes){
this.recipes = recipes;
}
@XmlElement
public List getRecipes() {
return recipes;
}
public void setRecipes(List recipes) {
this.recipes = recipes;
}
}
< /code>
Я пытаюсь управлять строкой XML, которую можно преобразовать в массиве объектов.
Ошибка дайте мне это сообщение, что список пуст, я думаю, я думаю, Но я не понимаю, почему, спасибо за помощь.
Подробнее здесь: https://stackoverflow.com/questions/718 ... rexception