方法开始元素(字符串,字符串,字符串,属性)的类型..必须重写或实现超类型方法



我使用 SAX 解析器,当我@Override添加到

public void startElement(String namespaceURI, String localName, String qName, 
        Attributes atts) throws SAXException {
    //Do somethink :)
}

我有错误:

方法startElement(字符串,字符串,字符串,属性)类型为...必须重写或实现超类型方法

更新

底部我添加此文件的完整代码。如果你想要其他想法,告诉我:)

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

导入这个...

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 {
    }
}

最新更新