Android上的简单XML框架,类属性

发布于 2024-12-26 13:46:25 字数 795 浏览 2 评论 0原文

我在 android 上的 simplexml 框架上遇到了一个奇怪的问题。我正在尝试从 xml 源读取并填充一个名为weatherdata 的对象。

XML 文件(对此没有控制):

<weatherdata>
    <product class="pointData">
        ....
    </product>
</weatherdata>

所以我的 java 文件看起来像:

@Root(name = "weatherdata", strict=false)
public class Weatherdata {

    @Element(name="product", required = true)
    protected ProductType product;

但我收到一个非常奇怪的错误:

01-14 14:22:28.919: W/System.err(18011): java.lang.ClassNotFoundException: pointData in loader dalvik.system.PathClassLoader

如果我尝试在 @Element 字段中 class=ProductType.class,它并不关心。即使我使用构造函数在项目中创建 pointData 类,错误也不会改变。它看起来像“class”作为保留关键字与简单的 xml 框架 2.6.2 的混乱。

我无法更改 xml。知道我该如何解决这个问题吗?谢谢。

Ive got a weird problem with simplexml framework on android. Im trying to read and fill an object called weatherdata from a xml source.

XML File (no control on this one):

<weatherdata>
    <product class="pointData">
        ....
    </product>
</weatherdata>

So my java file looks like :

@Root(name = "weatherdata", strict=false)
public class Weatherdata {

    @Element(name="product", required = true)
    protected ProductType product;

But I get a very weird error :

01-14 14:22:28.919: W/System.err(18011): java.lang.ClassNotFoundException: pointData in loader dalvik.system.PathClassLoader

If i try to class=ProductType.class in the @Element field, it doesn't care. Even when I create the pointData class in my projet with a constructor, the error doesnt change. It looks like "class" as a reserved keyword mess with simple xml framework 2.6.2.

I can't change the xml. Any idea how I could solve that ? thanks ahead.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤寂小茶 2025-01-02 13:46:25

尝试使用 TreeStrategy 将“类”替换为其他内容。

Strategy strategy = new TreeStrategy("clazz", "len"); // clazz substitute for class,
                                                      // and len for array lengths
Serializer serializer = new Persister(strategy);

Try using TreeStrategy to substitute the "class" for something else.

Strategy strategy = new TreeStrategy("clazz", "len"); // clazz substitute for class,
                                                      // and len for array lengths
Serializer serializer = new Persister(strategy);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文