0

Simple Framework を使用して xml ファイルを解析しています。親ノードを持たないリストを除いて、必要なものはすべて解析できます。「category.xml」の下のコード スニペットは、xml 形式と親のないカテゴリのリストを示しています。Categoryclass と my Root classのコードも含めましたArrayOfTypeCategory。解決策は簡単だとおかしな感じがありますが、指でしか触れられません。それは何か関係があり(inline=true)ますか?どんな助けでも大歓迎です。

---category.xml---

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCategory xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ACCUMobileWS.org/">
  <Category>
    <CategoryId>99</CategoryId>
    <Name>Frank</Name>
    <Description>Prison Break</Description>
  </Category>
  <Category>
    <CategoryId>101</CategoryId>
    <Name>Jim</Name>
    <Description>Breakig Bad</Description>
  </Category>
</ArrayOfCategory>

---カテゴリ クラス---

package com.SimpleFramwork;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Text;

@Element
public class Category {

@Text
public String CategoryId;

@Text
public String Name;

@Text
public String Description;

}

---ArrayOfTypeCategory クラス----

package com.SimpleFramwork;

//imports

import java.util.List;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

@Root
public class ArrayOfCategory {

@ElementList(inline = true)
private List<Category> list;

public List getCategories() {
    return list;
}
}

プロジェクトを実行すると、log cat にこのエラーが表示されます '

org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=, required=true, type=void) on field 'list' private java.util.List com.SimpleFramwork.ArrayOfCategory.list for class com.SimpleFramwork.ArrayOfCategory at line 2'
4

1 に答える 1

1

内部値を要素にする必要があります。

@Element
public class Category {

    @Element
    public String CategoryId;

    @Element
    public String Name;

    @Element
    public String Description;    
}
于 2012-09-06T09:56:16.950 に答える