我使用SAX Parser并将 @Override 添加到
public void startElement(String namespaceURI, String localName, String qName,
Attributes atts) throws SAXException {
//Do somethink :)
}
我有错误:
类型为...的方法startElement(String,String,String,Attributes)必须覆盖或实现超类型方法
下面我添加了这个文件的完整代码。如果你想要任何其他想法告诉我:)
import java.util.ArrayList;
import java.util.jar.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
public class ParseGEOLocal extends DefaultHandler {
String tempLoc;
private static ArrayList<Locations> locations;
private Locations location;
public ParseGEOLocal() {
super();
locations = new ArrayList<Locations>();
}
public static ArrayList<Locations> getLocations() {
return locations;
}
@Override
public void startElement(String namespaceURI, String localName, String qName,
Attributes atts) throws SAXException {
if(qName.equalsIgnoreCase("Result")){
location = new Locations();
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
tempLoc = new String(ch, start, length);
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if(localName.equalsIgnoreCase("Result"))
locations.add(location);
else if(localName.equalsIgnoreCase("city"))
location.setCity(tempLoc);
else if(localName.equalsIgnoreCase("uzip"))
location.setUzip(tempLoc.replaceAll("[\\s\\-()]", ""));
else if(localName.equalsIgnoreCase("woeid"))
location.setWOEID(tempLoc);
}
}
答案 0 :(得分:2)
导入此...
import org.xml.sax.Attributes;
而不是......
import java.util.jar.Attributes;
检查这些是否与您的......
相符import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SSAXParserHandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
}
}