使用 Wordpress 数据时遇到问题

发布于 2024-11-07 19:56:44 字数 3818 浏览 0 评论 0原文

我正在编写一个应用程序,它使用 wordpress-java 库来显示中的每篇文章ListView(很像纽约时报应用程序和其他类似的新闻应用程序)。这是每当我尝试获取数据(从模拟器和我的手机(摩托罗拉 Droid))时得到的完整堆栈跟踪:

05-16 23:00:45.800: WARN/System.err(1198): redstone.xmlrpc.XmlRpcException: The response could not be parsed.
05-16 23:00:45.839: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.handleResponse(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.endCall(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.invoke(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcProxy.invoke(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at net.bican.wordpress.$Proxy1.getRecentPosts(Native Method)
05-16 23:00:45.847: WARN/System.err(1198):     at net.bican.wordpress.Wordpress.getRecentPosts(Wordpress.java:497)
05-16 23:00:45.847: WARN/System.err(1198):     at namespace.onCreate(Test.java:28)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-16 23:00:45.847: WARN/System.err(1198):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 23:00:45.847: WARN/System.err(1198):     at android.os.Looper.loop(Looper.java:123)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-16 23:00:45.847: WARN/System.err(1198):     at java.lang.reflect.Method.invokeNative(Native Method)
05-16 23:00:45.847: WARN/System.err(1198):     at java.lang.reflect.Method.invoke(Method.java:521)
05-16 23:00:45.847: WARN/System.err(1198):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-16 23:00:45.847: WARN/System.err(1198):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-16 23:00:45.847: WARN/System.err(1198):     at dalvik.system.NativeStart.main(Native Method)
05-16 23:00:45.847: WARN/System.err(1198): Caused by: redstone.xmlrpc.XmlRpcException: Could not instantiate XMLReader parser
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcParser.parse(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     ... 20 more
05-16 23:00:45.847: WARN/System.err(1198): Caused by: org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?
05-16 23:00:45.847: WARN/System.err(1198):     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:157)
05-16 23:00:45.847: WARN/System.err(1198):     ... 21 more

但是,当我将完全相同的代码放入简单的 Java 应用程序时,我能够查询一切数据正常。在清单中,我启用了 android.permission.INTERNET 的权限。我还需要启用什么其他功能吗?我浏览了其他人,其他人似乎都没有提到任何与数据相关的东西(我唯一需要的东西)。

这是 Java 应用程序的代码(Android 看起来几乎相同,加上 ListView 代码)

    String username = "username";
    String password = "password";
    String xmlRpcUrl = "http://www.example.com/xmlrpc.php";

    try
    {
        Wordpress wp = new Wordpress(username, password, xmlRpcUrl);            
        List<Page> recentPosts = wp.getRecentPosts(10);

        for (Page p : recentPosts)
        {
            System.out.println(p.getTitle());
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

I'm writing an application that uses the wordpress-java library to display each article in a ListView (much like the NYTimes app, and other similar news apps). Here is the full stack trace I get whenever I try to grab the data (both from the emulator and from my phone(Motorola Droid)):

05-16 23:00:45.800: WARN/System.err(1198): redstone.xmlrpc.XmlRpcException: The response could not be parsed.
05-16 23:00:45.839: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.handleResponse(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.endCall(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcClient.invoke(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcProxy.invoke(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     at net.bican.wordpress.$Proxy1.getRecentPosts(Native Method)
05-16 23:00:45.847: WARN/System.err(1198):     at net.bican.wordpress.Wordpress.getRecentPosts(Wordpress.java:497)
05-16 23:00:45.847: WARN/System.err(1198):     at namespace.onCreate(Test.java:28)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-16 23:00:45.847: WARN/System.err(1198):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 23:00:45.847: WARN/System.err(1198):     at android.os.Looper.loop(Looper.java:123)
05-16 23:00:45.847: WARN/System.err(1198):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-16 23:00:45.847: WARN/System.err(1198):     at java.lang.reflect.Method.invokeNative(Native Method)
05-16 23:00:45.847: WARN/System.err(1198):     at java.lang.reflect.Method.invoke(Method.java:521)
05-16 23:00:45.847: WARN/System.err(1198):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-16 23:00:45.847: WARN/System.err(1198):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-16 23:00:45.847: WARN/System.err(1198):     at dalvik.system.NativeStart.main(Native Method)
05-16 23:00:45.847: WARN/System.err(1198): Caused by: redstone.xmlrpc.XmlRpcException: Could not instantiate XMLReader parser
05-16 23:00:45.847: WARN/System.err(1198):     at redstone.xmlrpc.XmlRpcParser.parse(Unknown Source)
05-16 23:00:45.847: WARN/System.err(1198):     ... 20 more
05-16 23:00:45.847: WARN/System.err(1198): Caused by: org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?
05-16 23:00:45.847: WARN/System.err(1198):     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:157)
05-16 23:00:45.847: WARN/System.err(1198):     ... 21 more

However, when I throw the exact same code into a simple Java app, I am able to query all the data normally. In the Manifest I have enabled permission to android.permission.INTERNET. Is there anything else that I need to enable? I looked through the others and none of the others seem to refer to anything data-related (the only thing I need).

Here is the code from the Java app (the Android looks pretty much the same, plus the ListView code)

    String username = "username";
    String password = "password";
    String xmlRpcUrl = "http://www.example.com/xmlrpc.php";

    try
    {
        Wordpress wp = new Wordpress(username, password, xmlRpcUrl);            
        List<Page> recentPosts = wp.getRecentPosts(10);

        for (Page p : recentPosts)
        {
            System.out.println(p.getTitle());
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

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

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

发布评论

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

评论(1

望喜 2024-11-14 19:56:44

如果发生套接字错误(因此连接错误)、Web 服务返回的 XML 无法解析(因此服务器错误)或响应以外的响应,则 wordpress-java 使用的 Redstone XML-RPC 库中会发生该特定错误。收到 HTTP 200。如果没有完整的堆栈跟踪,很难判断它是哪一个,但我怀疑完全相同的代码是否可以在桌面上运行但不能在 Android VM 中运行,并且您拥有 INTERNET 权限,表明存在连接问题(您是否使用模拟器或具有实时连接的设备)?

包含完整的堆栈转储(使用 android.util.Log.v("WPJAVA", "Exception ["+e.getMessage()+"]", e); 而不是仅 Android 上的 e.printStackTrace())。

编辑:并且,您已经有了答案:

05-16 23:00:45.847: WARN/System.err(1198): Caused by: org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?

尝试在调用红石函数之前执行此操作:

System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");

That particular error happens in the Redstone XML-RPC library used by wordpress-java if either a socket error occured (so a bad connection), the XML returned by the web service was unparseable (so a server error), or a response other than HTTP 200 was received. Without a full stack trace its hard to tell which one it is, but I'd suspect if the exact same code worked on the desktop but not in the Android VM and you have the INTERNET permission that you have a connectivity issue (are you using an emulator or a device with a live connection)?

Include a full stack dump (use android.util.Log.v("WPJAVA", "Exception ["+e.getMessage()+"]", e); instead of just e.printStackTrace() on Android).

EDIT: And, you have your answer:

05-16 23:00:45.847: WARN/System.err(1198): Caused by: org.xml.sax.SAXException: Can't create default XMLReader; is system property org.xml.sax.driver set?

Try executing this before you call the redstone functions:

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