Android: Error when using Retrofit with XML Converter

1

I'm doing a simple example of Retrofit on Android with an XML converter, but every time I run I get the following exception:

java.lang.RuntimeException: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Element(data=false, name=title, required=true, type=void) on field 'title' private java.lang.String com.rdev.testes.Channel.title for class com.rdev.testes.Channel at line 2

The format of my XML is:

<rss version="2.0">
<channel>
 <title>Testes</title>
 <description>Primeira Descrição</description>
 <link>http://teste.html</link>
 <item>
  <title>Teste numero 5 - 31/10/2017</title>
  <description>
      Descrição teste
  </description>
  <link>
     http://teste.html
  </link>
 </item>
</channel>
</rss>

Channel class:

@Root(name="rss", strict=false)
public class Channel {

@Element(name = "title")
private String title;

@Element(name = "description")
private String description;

@Element(name = "link")
private String link;

private Item horoscopeDescription;

public String getTitle() {return title;}

public void setTitle(String title) {this.title = title;}

public String getDescription() { return description;}

public void setDescription(String description) { this.description= description;}

public Item getHoroscopeDescription(){ return this.horoscopeDescription;}

public void setLink(String title) { this.link = link;}

public String getLink(String title) { return link;}   

Class Item:

@Root (name="item", strict = false) public class Item {

@Element(name = "title")
private String title;

@Element(name = "description")
private String description;

public String getTitle() {return title;}

public void setTitle(String title) {this.title = title;}

public String getDescription() {return description;}

public void setDescription(String description) {this.description = description;}

}

I have read several pages on this topic, but I can not find a solution. Can anyone help?

    
asked by anonymous 31.10.2017 / 22:40

1 answer

1

You have marked the title attribute as required (this is the default setting). At some point you're getting a XML without the title element .

Try to explicitly mark required as false

@Element(name = "title",required = false)
private String title;
    
01.11.2017 / 03:00