问答详情
源自:3-4 使用 SAX 解析将 XML 的内容和结构存入 JAVA 对象

handler.getSaxBooks().size() 出错 显示The method getSaxBooks() is undefined for the type SAXParserHandler明明定义了的 为什么还是显示没有这个方法呢?

package xml;

import java.io.IOException;
import java.util.logging.Handler;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import defaulthandler.SAXParserHandler;

public class SaxTest {

 public static void main(String[] args) {
SAXParserFactory factory=SAXParserFactory.newInstance();
try {
 SAXParser parse=factory.newSAXParser();
 SAXParserHandler handler=new SAXParserHandler();
  parse.parse("src/res/books.xml", handler);
  
  
  System.out.println("共存储了"+handler.getSaxBooks().size()+"本书");
  for (Books book : handler.getSaxBooks()) {
   System.out.println("id: "+book.getId());
   System.out.println("name: "+book.getName());
   System.out.println("author: "+book.getAuthor());
   System.out.println("language: "+book.getLanguage());
   System.out.println("price: "+book.getPrice());
   System.out.println("year: "+book.getYear());

  }
 
 
} catch (ParserConfigurationException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
} catch (SAXException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
}catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
}


 
 
 }
 
 
 

}

提问者:慕粉3347230 2016-06-07 14:07

个回答

  • peterme
    2016-07-11 22:13:51

    你应该把

    SAXParserHandler

    的源码发出来

  • 圊涩的苹果
    2016-06-17 15:34:49

    不是getBooklist()吗?


  • weibo_爱到头破血流心痛不已_03224046
    2016-06-07 15:17:49

    没在一个包下吧,那个方法是default不是public