我在我的应用程序中使用 jericho 解析器来获得一个更轻量级的网页版本,从中提取一些部分。所以,例如,当我得到这个代码时:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN/" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> </head> <body> <b> <span class="articletitletext">Happy New Year!</span></b> <br> <span class="postedstamp">Posted By <script language="JavaScript" type="text/javascript"> <!-- document.write('<a href=" mailto:chris.wyman@verizon.net">'); // --> </script>Chris</a> on January 1, 2012</span><br> <br> <span id="intelliTXT">
From all of us here at TheForce.net, we wish you and your family a safe and Happy New Year. May the Force be with you in 2012!
</span></body> </html>
我想使用 jericho 解析器再次解析它,但是当我运行时
ArrayList<Element> centerElems=(ArrayList<Element>) pageSource.getAllElements(HTMLElementName.CENTER);
我得到了这个例外
01-01 10:46:37.518: ERROR/AndroidRuntime(648): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.test.theforce/net.test.theforce.NewsListActivity}: java.lang.RuntimeException: java.lang.ClassCastException: java.util.Collections$EmptyList
并且应用程序崩溃了……那么,较轻的页面有什么问题?