views:

55

answers:

2

Hi--

I am trying to use an XMLPullParser to parse some XML for an android app. I am classpathing in android.jar from the android-8 SDK.

Alas, this code:

import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;

class InstantiateXMLPullParser {
  public static void main( String args[] ){
    XmlPullParser xpp = Xml.newPullParser();
  }
}

fails with this error:

Exception in thread "main" java.lang.RuntimeException: Stub!
        at android.util.Xml.newPullParser(Xml.java:15)
        at InstantiateXMLPullParser.main(InstantiateXMLPullParser.java:6)

I suspect I need to specify an implementation somewhere -- it looks like once upon a time Android used org.apache.harmony.xml.ExpatPullParser as its default pull parser, but that no longer seems to be the case.

+1  A: 

You seem to have more fundamental problems. java.lang.RuntimeException: Stub! will only come when you attempt to use android.jar outside of Android. Try building an Android application and running it on a device or emulator, and you will get your pull parser.

CommonsWare
yes, the problems are more fundamental. was trying to do some stubbing out of my own, outside of the heavy, slow emulator. thanks very much for your quick answer.
johnzo
A: 
import java.io.InputStream;

import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;

private InputStream input;

public class InstantiateXMLPullParser {
   static{
   .
   .
   .
   }
public InstantiateXMLPullParser(InputStream stream){
   this.input = stream;
   }
   .
   .
   .
}
triump