简体   繁体   中英

android xml pull parser?

The android developer site recommends the xml pull parser.. so I tried out its code (copied it to eclipse) and it gives no errors. But if you try to run it, it gives :

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/ref/FinalReference

So I scourged the internet, tried "solutions" posted online and it didn't help. On a whim, I try to locate org.xml but it isn't there ! so I download it and now am wondering where to save the bugger!

But maybe the problem isn't that at all. If you save the code as a simple java file, it says it cant find the packages (org.xml...)

So I guess the point of this is...

How do you run this program in eclipse (indigo) ?

import java.io.IOException;
import java.io.StringReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

public class Xml_readActivity
 {

 public static void main (String args[])throws XmlPullParserException, IOException
 {
     XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
     factory.setNamespaceAware(true);
     XmlPullParser xpp = factory.newPullParser();

     xpp.setInput( new StringReader ( "<foo>Hello World!</foo>" ) );
     int eventType = xpp.getEventType();
     while (eventType != XmlPullParser.END_DOCUMENT) {
      if(eventType == XmlPullParser.START_DOCUMENT) {
          System.out.println("Start document");
      } else if(eventType == XmlPullParser.START_TAG) {
          System.out.println("Start tag "+xpp.getName());
      } else if(eventType == XmlPullParser.END_TAG) {
          System.out.println("End tag "+xpp.getName());
      } else if(eventType == XmlPullParser.TEXT) {
          System.out.println("Text "+xpp.getText());
      }
      eventType = xpp.next();
     }
     System.out.println("End document");
 }
}

there is no problem in your code , you are just missing somthing to run it correctly. show your logcat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM