我有以下代码:
public static void main(String[] args)
throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document document = dBuilder.parse("NewFile.xml");
String usr = document.getElementsByTagName("username").item(0).getTextContent();
System.out.println(document);
}
这导致NullPointerException
String usr
行 <?xml version="1.0"?>
<tudorTestUser>
<propertySet>
<property name="username">TudorTest123</property>
<property name="firstName">Ion</property>
<property name="lastName">Vasile</property>
<property name="password">Tester123</property>
<property name="passwordAgain">Tester123</property>
<!-- <property name="location">Bucharest</property> -->
<property name="email">tester@test.com</property>
<property name="Status">active</property>
<property name="thirdParty">No Third Party</property>
<property name="agentID">Tester</property>
<property name="switch">on</property>
<property name="position">Web Master</property>
<property name="clone"></property>
<property name="overrideCode"></property>
</propertySet>
</tudorTe
。有什么想法吗?新文件放在工作区项目文件夹中,我也尝试给绝对路径没有成功。
XML文件:
@Column( nullable = true )
@JsonFormat( pattern = "yyyy-MM-dd HH:mm:ss" )
private Date dateSysteme;