2
如何获得一些infromation我怎么能得到一些信息(列,行,消息)在此代码?如何从设置在W3C验证器
String xhtml = "<html><body><p>Hello, world!<p></body></html>";
ValidationResponse response = new ValidatorBuilder().html().validate(xhtml);
if (!response.valid())
{
Set<Defect> errors = response.errors();
//... what write at this place?
System.out.println(errors[0].column() + " " + errors[0].source());
}
我试图为写:
String xhtml = "<html><body><p>Hello, world!<p></body></html>";
ValidationResponse response = new ValidatorBuilder().html().validate(xhtml);
if (!response.valid())
{
Set<Defect> errors = response.errors();
Defect[] errorsArray = (Defect[]) errors.toArray();
System.out.println(errorsArray[0].column() + " " + errorsArray[0].source());
}
但是得到的异常:在线程 “主要” java.lang.ClassCastException
例外:[Ljava.lang.Object;不能投射到[Lcom.rexsl.w3c.Defect; 在HTMLValidator.main(HTMLValidator.java:17)
可能重复(http://stackoverflow.com/questions/380813/downcasting-in-java) – 2013-10-18 00:38:24