simpleライブラリを使用してxmlが上手く読み込めない

757 views
Skip to first unread message

ている

unread,
Feb 22, 2013, 12:34:54 AM2/22/13
to android-g...@googlegroups.com
ていると申します。

ブラックジャックアプリを製作中です。
simpleライブラリを使用してxmlに格納されている値を読み込もうとしているのですが、
どうしてもエラーが発生してしまいます。

■xml本文
座標が格納されているデータ
pointmanager:ルート
pointshelf:画面。以下だとbj_gameなのでゲーム画面。
pointid:表示する画像ID。R.drawable.画像IDの値を自作関数にてこの文字列に変換しています。
pointkind:画面解像度によって表示位置を4種類に分けております。
point:座標
diff:位置の差分。とりあえず必要な値なので。

<?xml version="1.0" encoding="utf-8"?>

<pointmanager>

    <pointshelf name="bj_game">

        <pointid name="chip500">

            <pointkind>

                <point>

                    <x>10.27f</x>

                    <y>539.55f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>7.71f</x>

                    <y>404.66f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>5.14f</x>

                    <y>269.77f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>3.85f</x>

                    <y>202.33f</y>

                </point>

                <diff>0</diff>

            </pointkind>

        </pointid>

        <pointid name="chip100">

            <pointkind>

                <point>

                    <x>113.77f</x>

                    <y>539.55f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>85.331f</x>

                    <y>404.66f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>56.89f</x>

                    <y>269.77f</y>

                </point>

                <diff>0</diff>

            </pointkind>

            <pointkind>

                <point>

                    <x>42.66f</x>

                    <y>202.33f</y>

                </point>

                <diff>0</diff>

            </pointkind>

        </pointid>

--- 以下、繰り返しのため略 ---

    </pointshelf>

</pointmanager>


■各クラス
@Root
public class PointManager{
@ElementList(name="pointshelf")
public List<PointShelf> pointshelf;
}

public class PointShelf {
@ElementList(name="pointid")
public List<PointId> pointid;
@Attribute(name="name")
public String name;
}

public class PointId {
@ElementList(name="pointkind")
public List<PointKind> pointkind;
@Attribute(name="name")
public String name;
}

public class PointKind {
@ElementList(name="point")
public List<Point> point;
@Element(name="diff")
public String diff;
}

public class Point {
@Element(name="x")
public String x;
@Element(name="y")
public String y;
}

■xmlから値を取得する部分
InputStream is = context.getResources().openRawResource(R.raw.point);
Persister persister = new Persister();
try {
this.pManager = persister.read(PointManager.class, is, false);
}catch (Exception e){
System.out.println(e); // エラー出力。ココで下記のエラー
}

■表示エラー文 ※パッケージ名は変更しております。
02-12 13:48:57.538: I/System.out(13305): org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=pointid, required=true, type=void) on field 'pointid' public java.util.List com.hoge.blackjack.PointShelf.pointid for class com.hoge.blackjack.PointShelf at line 4


エラーを見る限りPointShelfにpointidが存在しないとのエラーのようですが、見ていただくと分かるとおり存在します。
また、required=falseを付与するとコンパイルは通りますが、帰ってくる値はnullなので座標データは取得できていません。
xml本文等かなり見にくいかとは思いますが、よろしくお願い致します。

ている

unread,
Mar 7, 2013, 5:41:37 AM3/7/13
to android-g...@googlegroups.com
この投稿から片手間に色々調べたりいじってはいるのですが、全く解決できません。
開発環境を入れ直したりもしてみたのですが、変わらずです。
どなたでも構わないのでご教授願えないでしょうか。

2013年2月22日金曜日 14時34分54秒 UTC+9 ている:

さとう

unread,
Mar 7, 2013, 8:14:18 AM3/7/13
to android-g...@googlegroups.com
さとうと申します。

simpleライブラリは使ったことがないのですが、
いきなり複雑なxmlを読み込ませるのではなく、
もっと簡単なxmlの読み込みからテストして
徐々に複雑なxmlに変えていけば、何が悪いか分かるのではないでしょうか?

例えば、
<a>
<b>aaa</b>
<b>bbb</b>
</a>
とか、

<a>
<b><c>aaa</c></b>
<b><c>bbb</c></b>
</a>

のような簡単なxmlはsimpleライブラリを使ってうまく読み出せているのでしょうか?
//


2013年3月7日 19:41 ている <tale...@gmail.com>:
> --
> このメールは Google グループのグループ「日本Androidの会」の登録者に送られています。
> このグループから退会し、メールの受信を停止するには、android-group-j...@googlegroups.com
> にメールを送信します。
> このグループに投稿するには、android-g...@googlegroups.com にメールを送信してください。
> http://groups.google.com/group/android-group-japan?hl=ja
> からこのグループにアクセスしてください。
> その他のオプションについては、https://groups.google.com/groups/opt_out にアクセスしてください。
>
>

Shin Miyazaki

unread,
Mar 7, 2013, 8:21:29 AM3/7/13
to android-g...@googlegroups.com
こんばんは、みやざきです。

このような場合、先にPointManagerのインスタンスを生成し、それをSimpleライブラリでxmlに
出力させてみることで、各クラスのannotation設定をどうすればいいかわかりやすいと思います。

今回の場合は@ElementListに inline と entry オプションを与えれば望む結果が得られるかと思います。


Reply all
Reply to author
Forward
0 new messages