SAXParseException和UnmarshaleException
我正试图处理这些例外情况。例如,当用户加载一个无效的XML文件时,会抛出SAXParseException,并要求他加载另一个文件 看来“抓”在这里不起作用 这是我的密码:SAXParseException和UnmarshaleException,exception,jaxb,Exception,Jaxb,我正试图处理这些例外情况。例如,当用户加载一个无效的XML文件时,会抛出SAXParseException,并要求他加载另一个文件 看来“抓”在这里不起作用 这是我的密码: public void parseXML_FROM_file (File xml_file) { try { JAXBContext jc = JAXBContext.newInstance ("generated"); //Creating an
public void parseXML_FROM_file (File xml_file)
{
try {
JAXBContext jc = JAXBContext.newInstance ("generated");
//Creating an Unmarshaller.
Unmarshaller u = jc.createUnmarshaller ();
//USING FILE APPROACH
System.out.println("Using FILE approach:");
JAXBElement element = (JAXBElement) u.unmarshal(xml_file);
TEST_Class mainTest = (TEST_Class) element.getValue ();
} catch (JAXBException e)
{
e.printStackTrace ();
}catch (SAXParseException e)
//do something
}catch (UnmarshalException e)
//do something
}
}
即使这样,也不行
catch (JAXBException,SAXParseException,UnmarshalException e)
{
//do something
}
@唐·罗比
这就是我得到的:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type JAXBException is not generic; it cannot be parameterized with arguments <SAXParseException, UnmarshalException>
Syntax error on token ",", < expected
Syntax error, insert ">" to complete ReferenceType1
at XML_Parser.parseXML_FROM_file(XML_Parser.java:64)
at Main_Class.main(Main_Class.java:13)
线程“main”java.lang中出现异常。错误:未解决的编译问题:
类型jaxbeexception不是泛型的;不能使用参数对其进行参数化
令牌“,”上的语法错误,<预期值
语法错误,请插入“>”以完成引用类型1
在XML_Parser.parseXML_处,从_文件(XML_Parser.java:64)读取
在Main_Class.Main(Main_Class.java:13)
异常表示这是一个编译异常。一旦在XML_解析器类中修复了错误,您就应该获得预期的JAXB行为
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type JAXBException is not generic; it cannot be parameterized with arguments <SAXParseException, UnmarshalException>
Syntax error on token ",", < expected
Syntax error, insert ">" to complete ReferenceType1
at XML_Parser.parseXML_FROM_file(XML_Parser.java:64)
at Main_Class.main(Main_Class.java:13)
线程“main”java.lang中出现异常。错误:未解决的编译问题:
类型jaxbeexception不是泛型的;不能使用参数对其进行参数化
令牌“,”上的语法错误,<预期值
语法错误,请插入“>”以完成引用类型1
在XML_Parser.parseXML_处,从_文件(XML_Parser.java:64)读取
在Main_Class.Main(Main_Class.java:13)
它以什么方式不工作?你看到的是什么行为?