Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:18:35+00:00 2026-05-27T21:18:35+00:00

I use jericho parser in my application to get a lighter version of a

  • 0

I use jericho parser in my application to get a lighter version of a web page, extracting some parts from it. So, for instance, when I get this code:

<!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="&#32;&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#99;&#104;&#114;&#105;&#115;&#46;&#119;&#121;&#109;&#97;&#110;&#64;&#118;&#101;&#114;&#105;&#122;&#111;&#110;&#46;&#110;&#101;&#116;">'); // --> </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>

I’d like to parse it once again using jericho parser, but when I run

ArrayList<Element> centerElems=(ArrayList<Element>) pageSource.getAllElements(HTMLElementName.CENTER);

I got this exception

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

and the application crashes…so, what’s wrong with the lighter page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:18:35+00:00Added an answer on May 27, 2026 at 9:18 pm

    It looks to me like the Jericho parser can parse the HTML you gave it. The error you’re getting arises because you’ve made an incorrect assumption about what the getAllElements() method returns.

    I admit I could only find the Javadoc for the zero-argument overload of this method, as opposed to the one-argument overload that you’re using, so I’ll have to assume that both methods return the same type, List<Element>. In your example, there are no center elements in the HTML, so the getAllElements() method should return an empty List<Element>. It doesn’t have to return an ArrayList<Element> here; any implementation of List<Element> will do. In this case, it chooses to return a Collections.emptyList(). This isn’t an ArrayList<Element>, and you get a ClassCastException because you cannot cast this to an ArrayList<Element>.

    As far as I can see, you have two options:

    • Firstly, you might not need the returned list to be an ArrayList<Element>. It might be sufficient to use List<Element> instead. In this case, you should replace the line

      ArrayList<Element> centerElems=(ArrayList<Element>) pageSource.getAllElements(HTMLElementName.CENTER);
      

      with

      List<Element> centerElems = pageSource.getAllElements(HTMLElementName.CENTER);
      
    • Secondly, if you really do need the list to be an ArrayList<Element>, then you can create an ArrayList<Element> from the results:

      ArrayList<Element> centerElems = new ArrayList<Element>(pageSource.getAllElements(HTMLElementName.CENTER));
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Jericho HTML Parser 3.1. I need to extract text from html, handle
Use case: 3rd party application wants to programatically monitor a text file being generated
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
We use a data acquisition card to take readings from a device that increases
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I
Use case: Fitnesse is used for automated testing of the web site. SUT (software
Use Eclipse Classic with ADT plugin. Tried to make project from existing example of
use strict; use Time::HiRes qw[gettimeofday tv_interval]; my $start_index = int(rand(50))+100;#this value is arbitrary for
Use scenario is pretty simple: I have a desktop only application that could be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.