我一直收到这个错误,我不知道如何解决它或它的意思是什么意思?谁能帮我?
Logcat:
02-07 21:57:55.801: W/System.err(9369): org.xmlpull.v1.XmlPullParserException: unterminated entity ref (position:TEXT @13:51 in java.io.BufferedReader@42ac6658)
02-07 21:57:55.801: W/System.err(9369): at org.kxml2.io.KXmlParser.readEntity(KXmlParser.java:1210)
02-07 21:57:55.801: W/System.err(9369): at org.kxml2.io.KXmlParser.readValue(KXmlParser.java:1392)
02-07 21:57:55.801: W/System.err(9369): at org.kxml2.io.KXmlParser.next(KXmlParser.java:390)
02-07 21:57:55.801: W/System.err(9369): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
02-07 21:57:55.801: W/System.err(9369): at com.flamand.parksniffer.eventhandling.XmlParser.getStackSitesFromFile(XmlParser.java:115)
02-07 21:57:55.801: W/System.err(9369): at com.flamand.parksniffer.fragments.EventsEventFragment$SitesDownloadTask.onPostExecute(EventsEventFragment.java:102)
02-07 21:57:55.801: W/System.err(9369): at com.flamand.parksniffer.fragments.EventsEventFragment$SitesDownloadTask.onPostExecute(EventsEventFragment.java:1)
02-07 21:57:55.801: W/System.err(9369): at android.os.AsyncTask.finish(AsyncTask.java:632)
02-07 21:57:55.801: W/System.err(9369): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-07 21:57:55.801: W/System.err(9369): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
02-07 21:57:55.801: W/System.err(9369): at android.os.Handler.dispatchMessage(Handler.java:102)
02-07 21:57:55.801: W/System.err(9369): at android.os.Looper.loop(Looper.java:136)
02-07 21:57:55.801: W/System.err(9369): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-07 21:57:55.801: W/System.err(9369): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 21:57:55.801: W/System.err(9369): at java.lang.reflect.Method.invoke(Method.java:515)
02-07 21:57:55.801: W/System.err(9369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-07 21:57:55.801: W/System.err(9369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-07 21:57:55.801: W/System.err(9369): at dalvik.system.NativeStart.main(Native Method)
解析器类:
package com.flamand.parksniffer.eventhandling;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.content.Context;
import android.util.Log;
public class XmlParser{
static final String KEY_EVENTS="events";
static final String KEY_EVENT="event";
static final String KEY_NAME="name";
static final String KEY_DATE="date";
static final String KEY_INFO="info";
static final String KEY_IMG="img";
public static List<Event> getStackSitesFromFile(Context ctx) {
// List of StackSites that we will return
List<Event> events;
events = new ArrayList<Event>();
// temp holder for current StackSite while parsing
Event curEvent = null;
// temp holder for current text value while parsing
String curText = "";
try {
// Get our factory and PullParser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Open up InputStream and Reader of our file.
FileInputStream fis = ctx.openFileInput("events.xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
// point the parser to our file.
xpp.setInput(reader);
// get initial eventType
int eventType = xpp.getEventType();
// Loop through pull events until we reach END_DOCUMENT
while (eventType != XmlPullParser.END_DOCUMENT) {
// Get the current tag
String tagname = xpp.getName();
// React to different event types appropriately
/**switch (eventType) {
case XmlPullParser.START_TAG:
if (tagname.equalsIgnoreCase(KEY_EVENT)) {
Log.d("Parksiffer", "Parsing started 9");
// If we are starting a new <event> block we need
//a new StackSite object to represent it
curEvent = new Event();
Log.d("Parksiffer", "Parsing started 6");
}
break;
case XmlPullParser.TEXT:
Log.d("Parksiffer", "Parsing started 3");
//grab the current text so we can use it in END_TAG event
curText = xpp.getText();
Log.d("Parksniffer", curText);
break;
case XmlPullParser.END_TAG:
Log.d("Parksiffer", "Parsing started 4");
if (tagname.equalsIgnoreCase(KEY_EVENT)) {
events.add(curEvent);
} else if (tagname.equalsIgnoreCase(KEY_INFO)) {
Log.d("Parksiffer", "Parsing info");
curEvent.setInfo(curText);
} else if (tagname.equalsIgnoreCase(KEY_NAME)) {
curEvent.setName(curText);
}
break;
default:
break;
}*/
if(eventType == XmlPullParser.START_TAG){
// If we are starting a new <event> block we need
//a new StackSite object to represent it
if(tagname.equals(KEY_EVENT)){
Log.d("Parksniffer", "699");
curEvent = new Event();
}
}
if(eventType == XmlPullParser.TEXT){
Log.d("Parksiffer", "Parsing started 3");
//grab the current text so we can use it in END_TAG event
curText = xpp.getText();
Log.d("Parksniffer", curText);
}
if(eventType == XmlPullParser.END_TAG){
Log.d("Parksiffer", "Parsing started 4");
if (tagname.equalsIgnoreCase("/"+KEY_EVENT)) {
events.add(curEvent);
} else if (tagname.equalsIgnoreCase("/"+KEY_INFO)) {
Log.d("Parksiffer", "Parsing info");
curEvent.setInfo(curText);
} else if (tagname.equalsIgnoreCase("/"+KEY_NAME)) {
curEvent.setName(curText);
}
}
//move on to next iteration
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
// return the populated list.
return events;
}
}
这是xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event>
<name>Sinterklaas Parade</name>
<info>Een zeer aangename stoet rond de stad Roeselare waar Sinterklaas de kinderen zal begroeten</info>
<img></img>
</event>
<event>
<name>Carnaval</name>
<info>Een evenement dat je zeker niet mag missen! Vier carnaval in Roeselare!</info>
<img></img>
</event>
</events>
如果还有其他需要,我会发布。你能解释一下为什么它给我这个错误,而我的xml文件(据我所知)是没有bug的吗?因为我看到的所有其他地方都是因为xml错误而且是的...无论如何感谢阅读