2014-03-05 223 views
1

我使用SAX解析器,当我添加@Override该方法的startElement(字符串,字符串,字符串,属性)型的......必须覆盖或实现超方法

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

我有错误:

The method startElement(String, String, String, Attributes) of type ... must override or implement a supertype method

UPDATE

底部I添加此文件的完整代码。如果你想anythink别人告诉我:)

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

显示类声明。你在扩展和实施什么? – DwB

回答

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 { 

    } 

} 
+0

'导入org.xml.sax.Attributes与另一个导入语句碰撞' – drozdzynski

+0

是啊......我已经看到它......并且我已经更新了我的答案......请看看它。 –