Trouble consuming WordPress data

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).

Read More

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();
    }

Related posts

Leave a Reply

1 comment

  1. 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");