我在一个Location
类中设置了一个方法来解析一个 xml 文件。但是当我尝试从主方法中的主类调用该方法时,它似乎没有被调用。
我设置了一个断点,locObj.parseNetwork();
但它永远不会被触发,println 在它执行之后所以不确定问题可能是什么。
有谁知道为什么parseNetwork
不被调用?
这就是我从 main 调用方法的方式:
public class GrailQuestMain {
public static void main(String[] args) throws Exception {
//Parse in the xml file
Location locObj = new Location();
locObj.parseNetwork();
//Start screen prompt
System.out.println("********************************GRAIL QUEST************************************");
System.out.println("-------------------------------------------------------------------------------");
System.out.println("-------------------------------------------------------------------------------");
System.out.println("Hit enter to begin your quest to Cyprus..");
new Scanner(System.in).nextLine();
System.out.println("Loaded..");
}
}
这是 Location 类中的实际方法,两个类都在同一个包中:
public class Location implements Lookable{
private List<AbstractGameCharacter> observers = new ArrayList<AbstractGameCharacter>();
private List<Thing> objects = new ArrayList<Thing>();
private List<Exit> exits = new ArrayList<Exit>();
private String name;
private String description;
public void enter(AbstractGameCharacter gc){
observers.add(gc);
}
public void exit(GameChacter gc){
observers.remove(gc);
}
public void parseNetwork() throws ParserConfigurationException, SAXException, IOException{
//Get the DOM Builder Factory
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
//Get the DOM Builder
DocumentBuilder builder = factory.newDocumentBuilder();
//Load and Parse the XML document
//document contains the complete XML as a Tree.
Document document =
builder.parse(new File("network.xml"));
NodeList locationName = document.getElementsByTagName("location name");
}
}
在方法调用之前添加了 println 并得到输出,但方法似乎仍然没有被调用: