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