Android - 损坏的 XML 解析示例

发布于 2024-11-30 16:18:55 字数 836 浏览 2 评论 0原文

自 API v. 11 发布以来,Android SDK 包含 XmlAdapter 示例,也引用自官方网站。该示例现在至少出现在 3 个文件夹中:android-11、android-12 和 android-13。它已经坏了。它声明的主要(但不仅仅是)问题 android.content.XmlDocumentProvider 提供程序无处可寻,包括 https://android.googlesource.com
Adapters.java 中也存在编译问题:

mContext cannot be resolved to a variable   line 973
mFrom cannot be resolved to a variable  line 938
mTo cannot be resolved to a variable    line 937
mTo cannot be resolved to a variable    line 939

android-developers 上有几个与此相关的问题,但没有答案。有人设法跟踪这个难以捉摸的 XmlDocumentProvider 并使示例正常工作吗? 最重要的是 - 亲爱的 Android 团队,您能修复示例或将其取出吗?

Android SDK since release of API v. 11 contains XmlAdapter sample which is also referenced from the official site. This sample appears now in at least 3 folders: android-11, android-12 and android-13. And it is broken. The main (but not only) problem it declares android.content.XmlDocumentProvider provider which is nowhere to be found including https://android.googlesource.com
There are also compilation problems in Adapters.java:

mContext cannot be resolved to a variable   line 973
mFrom cannot be resolved to a variable  line 938
mTo cannot be resolved to a variable    line 937
mTo cannot be resolved to a variable    line 939

There are few question related to this on android-developers but no answer. Did anyone managed to track this elusive XmlDocumentProvider and make the sample work?
And most importantly - dear Android team, can you ether fix the sample or pull it out?

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

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

发布评论

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

评论(4

昇り龍 2024-12-07 16:18:55

缺少的 XmlDocumentProvider 现在随 SDK 14 中的示例一起提供,并且该项目针对 SDK 8 及更高版本进行编译。但是,要成功运行它,您必须修改清单以指向正确的提供程序:

<provider android:name="com.example.android.xmladapters.XmlDocumentProvider"
       android:authorities="xmldocument" />

The missing XmlDocumentProvider is now shipping with the sample in SDK 14 and the project compiles against SDK 8 and above. To run it successfully however, you must modify the manifest to point to the correct provider:

<provider android:name="com.example.android.xmladapters.XmlDocumentProvider"
       android:authorities="xmldocument" />
故事与诗 2024-12-07 16:18:55

除了修复 Jeff Gilfelt 指出的 AndroidManifest.xml 之外,您还可以更改 Adapters.java 中的代码 XmlCursorAdapter 类(显示错误的文件),如下所示:

/**
 * Implementation of a Cursor adapter defined in XML. This class is a thin wrapper
 * of a SimpleCursorAdapter. The main difference is the ability to handle CursorBinders.
 */
private static class XmlCursorAdapter extends SimpleCursorAdapter implements ManagedAdapter {
    private Context mContext;
    private String mUri;
    private final String mSelection;
    private final String[] mSelectionArgs;
    private final String mSortOrder;
    private final int[] mTo;
    private final String[] mFrom;
    private final String[] mColumns;
    private final CursorBinder[] mBinders;
    private AsyncTask<Void,Void,Cursor> mLoadTask;



    XmlCursorAdapter(Context context, int layout, String uri, String[] from, int[] to,
            String selection, String[] selectionArgs, String sortOrder,
            HashMap<String, CursorBinder> binders) {

        super(context, layout, null, from, to);
        mContext = context;
        mUri = uri;
        mFrom = from;
        mTo = to;
        mSelection = selection;
        mSelectionArgs = selectionArgs;
        mSortOrder = sortOrder;
        mColumns = new String[from.length + 1];
        // This is mandatory in CursorAdapter
        mColumns[0] = "_id";
        System.arraycopy(from, 0, mColumns, 1, from.length);

        CursorBinder basic = new StringBinder(context, new IdentityTransformation(context));
        final int count = from.length;
        mBinders = new CursorBinder[count];

        for (int i = 0; i < count; i++) {
            CursorBinder binder = binders.get(from[i]);
            if (binder == null) binder = basic;
            mBinders[i] = binder;
        }
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        final int count = mTo.length;
        final int[] to = mTo;
        final CursorBinder[] binders = mBinders;

        for (int i = 0; i < count; i++) {
            final View v = view.findViewById(to[i]);
            if (v != null) {
                binders[i].bind(v, cursor, cursor.getColumnIndex(mFrom[i]));
            }
        }
    }
    ......
    ......
    ......

我从此处找到的代码中得到了答案:

Besides fixing the AndroidManifest.xml as pointed out by Jeff Gilfelt, you can also change the code XmlCursorAdapter class in Adapters.java (the file showing the errors) like this:

/**
 * Implementation of a Cursor adapter defined in XML. This class is a thin wrapper
 * of a SimpleCursorAdapter. The main difference is the ability to handle CursorBinders.
 */
private static class XmlCursorAdapter extends SimpleCursorAdapter implements ManagedAdapter {
    private Context mContext;
    private String mUri;
    private final String mSelection;
    private final String[] mSelectionArgs;
    private final String mSortOrder;
    private final int[] mTo;
    private final String[] mFrom;
    private final String[] mColumns;
    private final CursorBinder[] mBinders;
    private AsyncTask<Void,Void,Cursor> mLoadTask;



    XmlCursorAdapter(Context context, int layout, String uri, String[] from, int[] to,
            String selection, String[] selectionArgs, String sortOrder,
            HashMap<String, CursorBinder> binders) {

        super(context, layout, null, from, to);
        mContext = context;
        mUri = uri;
        mFrom = from;
        mTo = to;
        mSelection = selection;
        mSelectionArgs = selectionArgs;
        mSortOrder = sortOrder;
        mColumns = new String[from.length + 1];
        // This is mandatory in CursorAdapter
        mColumns[0] = "_id";
        System.arraycopy(from, 0, mColumns, 1, from.length);

        CursorBinder basic = new StringBinder(context, new IdentityTransformation(context));
        final int count = from.length;
        mBinders = new CursorBinder[count];

        for (int i = 0; i < count; i++) {
            CursorBinder binder = binders.get(from[i]);
            if (binder == null) binder = basic;
            mBinders[i] = binder;
        }
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        final int count = mTo.length;
        final int[] to = mTo;
        final CursorBinder[] binders = mBinders;

        for (int i = 0; i < count; i++) {
            final View v = view.findViewById(to[i]);
            if (v != null) {
                binders[i].bind(v, cursor, cursor.getColumnIndex(mFrom[i]));
            }
        }
    }
    ......
    ......
    ......

I got the answer from the code found here:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/example/android/xmladapters/Adapters.java?av=f

可是我不能没有你 2024-12-07 16:18:55

我得到了罗曼·盖伊的答复,嗯。我昨天打开的票现在有一个标签状态:FutureRelease,我想这意味着他们将在下一个版本中修复它。如需添加参考,请参阅 android-developers 上的讨论链接

I got answer from Romain Guy, well sort of. The ticket that I opened yesterday now has a tag Status: FutureRelease which I suppose means that they will fix it in the next release. For the added reference here's link to the discussion on android-developers

软糯酥胸 2024-12-07 16:18:55

我遇到了同样的错误并四处搜索,发现同样的问题已被问了很多次。我就是这样解决的。

有一个 XmlDocumentProvider我发现

我将 XmlDocumentProvider.java 复制到 XmlAdapter 项目中,并修改了 AndroidManifest.xml,将: 替换

<provider android:name="android.content.XmlDocumentProvider"
       android:authorities="xmldocument" /> 

为:

<provider android:name="com.example.android.xmladapters.XmlDocumentProvider"
   android:authorities="xmldocument" />

现在我能够获得 <代码>RssReaderActivity 工作。

I met the same error and searched around, found the same question has been asked for many times. This is how I fixed it.

There is a XmlDocumentProvider class I found.

I copied the XmlDocumentProvider.java into the XmlAdapter project and revised the AndroidManifest.xml by replacing:

<provider android:name="android.content.XmlDocumentProvider"
       android:authorities="xmldocument" /> 

with:

<provider android:name="com.example.android.xmladapters.XmlDocumentProvider"
   android:authorities="xmldocument" />

Now I am able to get the RssReaderActivity working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文