473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

can not find symbol class Head

Can any one help me?

I got a code for the parse method of Parser class in html parser library from the link

htmlparser.sourceforge.net/javadoc/index.html

the code is as follows

Expand|Select|Wrap|Line Numbers
  1. NodeList nl = parser.parse (null); // here is your two node list
  2.  NodeList heads = nl.extractAllNodesThatMatch (new TagNameFilter ("HEAD"))
  3.  if (heads.size () > 0) // there may not be a HEAD tag
  4.  {
  5.      Head head = heads.elementAt (0); // there should be only one
  6.      head.removeAll (); // clean out the contents
  7.      Tag title = new TitleTag ();
  8.      title.setTagName ("title");
  9.      title.setChildren (new NodeList (new TextNode ("The New Title")));
  10.      Tag title_end = new TitleTag ();
  11.      title_end.setTagName ("/title");
  12.      title.setEndTag (title_end);
  13.      head.add (title);
  14.  }
  15.  System.out.println (nl.toHtml ()); // output the modified HTML
  16.  
  17.  
but when i am running this code, i am getting an error

"cannot find symbol class Head"

i couldnt find a class named Head in the library..

what should i do??
Mar 15 '12 #1
8 2430
r035198x
13,262 8TB
I think it was a typing mistake in the code.
I suspect the line should have been
Expand|Select|Wrap|Line Numbers
  1. Tag head = heads.elementAt (0); // there should be only one
  2.  
instead of
Expand|Select|Wrap|Line Numbers
  1. Head head = heads.elementAt (0); // there should be only one
  2.  
Mar 15 '12 #2
But the Tag class does not have a method named removeAll(). so again error

can not find symbol method removeAll()
Mar 15 '12 #3
r035198x
13,262 8TB
I thought it could be a HeadTag but that doesn't seem to contain a removeAll method either.
Find out what type it is with
Expand|Select|Wrap|Line Numbers
  1.  System.out.println(heads.elementAt (0));
  2. //comment out the rest of the code
  3.  
Mar 15 '12 #4
the nodelist heads is null.. so heads.elementAt(0) is null

but input htmlpage has an headtag in it. i dont know why it is printing null
Mar 15 '12 #5
r035198x
13,262 8TB
But there is an
Expand|Select|Wrap|Line Numbers
  1. if (heads.size () > 0) // there may not be a HEAD tag
  2.  {
  3.  
If your code is going into that if then a HEAD tag is there.
Create a short version of the program and post the code and the html you are using.
Mar 15 '12 #6
actually i commented
Expand|Select|Wrap|Line Numbers
  1. if (heads.size () > 0){
  2. }
I am submitting the code and HTML code

Expand|Select|Wrap|Line Numbers
  1.  
  2.  import org.htmlparser.Parser;
  3.  import org.htmlparser.Tag;
  4.  import org.htmlparser.Text;
  5.  import org.htmlparser.util.ParserException;
  6.  import org.htmlparser.visitors.NodeVisitor;
  7.  import java.util.*;
  8. import org.htmlparser.filters.TagNameFilter;
  9. import org.htmlparser.nodes.TextNode;
  10. import org.htmlparser.NodeFilter;
  11. import org.htmlparser.util.NodeList;
  12.  
  13.  
  14.  public class MyVisitor1 extends NodeVisitor
  15.  {
  16.  
  17. String str="DOCUMENT/HTML"; 
  18. static Hashtable pages = new Hashtable();
  19. int i=1;
  20. static Enumeration names; 
  21.  
  22. static String str1=null;
  23.  
  24.      public MyVisitor1 ()
  25.      {
  26.  
  27.      }
  28.      public void visitTag (Tag tag)
  29.      {
  30.        //  System.out.println ("\n" + tag.getTagName ());
  31.  
  32.          str=str+"/"+tag.getTagName();
  33.  
  34.          pages.put("p"+i,str);
  35.          i=i+1;
  36.  
  37.      //    System.out.println ("\n" +str);
  38.      }
  39.      public void visitStringNode (Text string)
  40.      {
  41.  
  42.     String st=string.getText();
  43.  
  44.     if(!st.trim().equals(""))
  45.     {
  46.  
  47.     str=str+"/"+string.getText();
  48.      pages.put("p"+i,str); 
  49.     i=i+1; 
  50.  
  51.  
  52.     }
  53.      }
  54.  
  55.      public static void display()
  56.     {
  57.  
  58.     names = pages.keys();
  59.  
  60.     while(names.hasMoreElements()) 
  61.     {
  62.     str1 = (String) names.nextElement();
  63.     System.out.println("...................................................................\n");
  64.     System.out.println(str1+ ": " +pages.get(str1));
  65.     } 
  66. System.out.println("the size of hash table is ::"+pages.size());
  67.     }
  68.  
  69.      public void visitEndTag(Tag tag)
  70.     {
  71.     String starttag=tag.getTagName();
  72.     int n=str.lastIndexOf(starttag);
  73.     //System.out.println("last index is::"+n);
  74.  
  75.     if(n<0)
  76.     {
  77.         return;
  78.     }    
  79.     str= str.substring(0,n-1);
  80.     //System.out.println("substring is::"+str);
  81.  
  82.       }
  83.  
  84.      public static void main (String[] args) throws ParserException
  85.      {
  86.  
  87.           Parser parser = new Parser ("E:/project/docs/d6.html");
  88.  
  89.     NodeList nl = parser.parse (null); // here is your two node list
  90.      NodeList heads = nl.extractAllNodesThatMatch (new TagNameFilter ("head"));
  91.  
  92.      //if (heads.size () > 0) // there may not be a HEAD tag
  93.      //{
  94.     System.out.println("hello"+heads.elementAt (0));
  95.          //Tag head =(Tag)heads.elementAt (0); // there should be only one
  96.         //head.removeAll (); // clean out the contents
  97.  
  98.     //}
  99.  
  100.          MyVisitor1 visitor = new MyVisitor1 ();
  101.  
  102.          nl.visitAllNodesWith (visitor);
  103.     //display();
  104.      }
  105.  }  
  106.  
  107.  
here is the html inout

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title> hai</title>
  5. </head>
  6. <body>
  7. <h1>tech</h1>
  8. <br />
  9. </body>
  10. </html>
  11.  
  12.  
Mar 15 '12 #7
r035198x
13,262 8TB
Use
Expand|Select|Wrap|Line Numbers
  1. NodeList heads = nl.extractAllNodesThatMatch(new TagNameFilter("HEAD"), true);
  2. Tag head =(Tag)heads.elementAt (0); // there should be only one
  3. System.out.println(head);
  4.  
You'd have to check the Javadocs to see what that true flag does.
Mar 15 '12 #8
Thanks a lot.. I got it..
Mar 15 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Bjorn Jensen | last post by:
Hi! An beginner question: Pleas help me with this (-: Error (the arrow points on the s in sqrt) ===== tal.java:6: cannot find symbol symbol : method sqrt(int) location: class tal...
1
by: Shiva48 | last post by:
Thanks to Gannon11 and ro351988- Moderator. I give below the complete Java file and pls help me to rectify the errors. package com.wrox.proj2ee.ch10.app; import java.io.*; import...
4
by: jingchua | last post by:
Hi, can anyone help out here???? I have the below error after compling the file. Any idea what is wrong in the declaration that was done in the above code??? Appreciate any help on shedding some...
2
by: jazzyme2 | last post by:
New to Java. Working on this and ran into this problem. Any clues? java:42: cannot find symbol symbol : constructor Pay() location: class Pay Pay Emp1 = new Pay(); ^ 43:...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
10
by: CodeNoob | last post by:
please help been working on a project got it down to 5 errors from 100 now i have no idea what to do. Errors: init: deps-jar: Created dir: C:\Users\Tommy\Desktop\build\classes Compiling 306...
2
suzee_q00
by: suzee_q00 | last post by:
Compiler seems to be hanging up on "new" but I know it isn't but I can't seem to figure out what it is that it doesn't like. Been chasing my tail for the last couple of days. Any help would be...
4
by: LadiPrather | last post by:
These error say there is not symbols, I have changed them some many times till I am lost. Please someone help. JOptionPane.showMessageDialog(null,"Oringinal Balance = $" + recieveAmount + ...
1
by: monkey0525 | last post by:
I'm writing a program that reads information from three seperate classes. Here is my code: public class Animal { protected int id; protected String type; protected double mass; ...
1
by: JanineXD | last post by:
Hey, I seem to have a problem on a Java Swing Program with ActionListener. I've tried to use getSource in our class but seem don't have an idea why it won't work when I tried to program at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.