Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2983 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  erreur "not a statement" en java

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

erreur "not a statement" en java

n°1883339
miss5
Posté le 11-05-2009 à 17:52:41  profilanswer
 

bonjour,
je suis en train de compiler un programme java dont voici le code:

Code :
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package htmlparser;
  6. /**
  7. *
  8. * @author sabrina
  9. */
  10. import java.io.BufferedWriter;
  11. import java.io.File;
  12. import java.io.FileWriter;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.text.DecimalFormat;
  16. import java.util.HashMap;
  17. import java.util.Vector;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import org.htmlparser.Parser;
  21. import org.htmlparser.filters.NodeClassFilter;
  22. import org.htmlparser.tags.LinkTag;
  23. import org.htmlparser.tags.TitleTag;
  24. import org.htmlparser.util.NodeList;
  25. import org.htmlparser.util.ParserException;
  26. import org.htmlparser.beans.StringBean;
  27. import java.util.Enumeration;
  28. import java.io.IOException;
  29. public class HtmlParser {
  30.     /**
  31.      * @param args the command line arguments
  32.      */
  33.      // define l'url  de site à aspirer
  34.         private static final String URLSite = "";
  35.         //extensions  permises à analyser
  36.         private static final Vector ExtensionPermises = new Vector();
  37.         static {
  38.                ExtensionPermises.add(".html" );
  39.                ExtensionPermises.add(".htm" );
  40.                ExtensionPermises.add(".jsp" );
  41.                ExtensionPermises.add(".php" );
  42.                ExtensionPermises.add(".aspx" );
  43.                 }
  44.         //  propriétés de bases
  45.         private URL SiteInitial;
  46.         private String Domaine;
  47.         HashMap URLVisité = new HashMap();
  48.         Vector URLaVisité = new Vector();
  49.         Vector URLpage = new Vector();
  50.         Vector URLp = new Vector();
  51.         Vector liste_page = new Vector();
  52.         Vector liste_page_f = new Vector();
  53.           File fichier = new File("fichier.txt" );
  54.  
  55.         int i=0;
  56.         //  options d'aspiration
  57.         private final int maxURLaVisité = 20;
  58.         private final boolean MemeDomaine = true;
  59.         // verbosity options
  60.         private final boolean reduit = true;
  61.         private final boolean URLInvalide = false;
  62.         private final boolean DomaineInvalid = false;
  63.         private final DecimalFormat df;
  64.         private String format(String string) { return string.replaceAll("\n", "" ).replaceAll("\\s+", " " ).trim(); }
  65.         private String base(URL url) { return url.getProtocol() + "://" + url.getHost() + url.getFile(); }
  66.         public HtmlParser(String url) {
  67.            
  68.            
  69.                 // initialisation de propriété de l'aspirateur
  70.                 try {
  71.                         SiteInitial = url.startsWith("www." ) ? new URL("http://"+url) : new URL(url);
  72.                     }   catch (MalformedURLException e) {
  73.                         e.printStackTrace();
  74.                 }
  75.                
  76.                 URLaVisité.add(SiteInitial);
  77.                 String[] domain = SiteInitial.getHost().split("\\." );
  78.                 Domaine = domain[domain.length - 2] + "." + domain[domain.length-1];
  79.                 StringBuffer format = new StringBuffer();
  80.                 for (int j = 0; j < maxURLaVisité ; j++) format.append("0" );
  81.                 df = new DecimalFormat(format.toString());
  82.         }
  83.         public void run() {
  84.          
  85.                 // Aspirer le web
  86.                 while (URLVisité.size() <= maxURLaVisité && URLaVisité.size() != 0) {
  87.                         try {
  88.                                 if (URLVisité.get(new URL(base((URL)URLaVisité.get(0)))) == null) visit((URL)URLaVisité.get(0));
  89.                          } catch (MalformedURLException e) {}
  90.                         URLaVisité.remove(0);
  91.                 }
  92.                 /*if (!reduit) {
  93.                         System.out.println("" );
  94.                         Set set = URLVisité.entrySet();
  95.                         Iterator x = set.iterator();
  96.                         int num = 1;
  97.                         //while ( i.hasNext() ) {
  98.                                // Entry entry = i.next();
  99.                               //  System.out.println(df.format(num++) + " url : " + entry.getKey().toString() + " - title : " + format(entry.getValue()));
  100.                         //}
  101.                 }*/
  102.         }
  103.         private void visit(URL url) {
  104.                 if ( URLVisité.size() >= maxURLaVisité ) return;
  105.                 String path = url.getPath();
  106.                 int lastDot = path.lastIndexOf("." );
  107.                 if(lastDot > 0 && !ExtensionPermises.contains(path.substring(lastDot))) return;
  108.                 if (url.toString().startsWith("mailto:" )) return;
  109.            
  110.                 /*if (MemeDomaine) {
  111.                         String[] domain = url.getHost().split("\\." );
  112.                         if ( domain.length < 3 ) return;
  113.                         if ( !Domaine.equals(domain[domain.length - 2] + "." + domain[domain.length-1])) {
  114.                                 if (reduit && DomaineInvalid)
  115.                                         System.err.println("Not same domain : (" + domain[domain.length - 2] + "." + domain[domain.length-1] +" ) " + url.toString());
  116.                                 return;
  117.                         }
  118.                 }*/
  119.               // créer une instance page et ajouter son url et l'url père
  120.               page1 p1=new page1();
  121.               p1.set(url.toString(),url.getHost());
  122.                 try {
  123.                         // extraire le titre de la  page  et les liens
  124.                         Parser parser = new Parser(url.toString());
  125.                         NodeList titreList = parser.parse(new NodeClassFilter (TitleTag.class));
  126.                         String titre = (titreList.size() != 0) ? ((TitleTag) titreList.elementAt(0)).getTitle() : "";
  127.                         // extraire le texte de la page
  128.                         StringBean sb = new StringBean ();
  129.                         sb.setLinks (false);
  130.                         sb.setReplaceNonBreakingSpaces(true);
  131.                         sb.setCollapse(true);
  132.                         sb.setURL(url.toString());
  133.                         String s1="rrrrrr" +"\n";
  134.                         String s = sb.getStrings();
  135.                        
  136.                      // créer un fichier qui va contenir le text
  137.                  
  138.                 File monfic = new File ("unfic"+i+".txt" );
  139.              
  140.                
  141.                        try
  142. BufferedWriter sortie = new BufferedWriter(new FileWriter("mots.txt", true));
  143. sortie.write("fichier \n" );
  144. sortie.write("unfic"+i+".txt"+"\n" );
  145.                 } catch (IOException ex) {
  146.                 Logger.getLogger(HtmlParser.class.getName()).log(Level.SEVERE, null, ex);
  147.             }
  148.             try {
  149.                 FileWriter infic = new FileWriter(monfic);
  150.                
  151.                 infic.write(s);
  152.             } catch (IOException ex) {
  153.                 Logger.getLogger(HtmlParser.class.getName()).log(Level.SEVERE, null, ex);
  154.             }
  155.                
  156.          
  157.                  i++;
  158.              
  159.          
  160.                    
  161.                 parser.reset();
  162.                 NodeList list = parser.parse (new NodeClassFilter (LinkTag.class));
  163.                 //  l'URL est noté comme visité
  164.                 URLVisité.put(new URL(base(url)), titre);
  165.                 /*if (reduit)*/ System.out.println(df.format(URLVisité.size()) + " url : " + url.toString() + " - titre : " + format(titre) + "- contenu :\n" + s);
  166.                 //else System.out.print("." );
  167.                 // saisir le nouveau lien à visiter
  168.             for (int y = 0; y < list.size(); y++) {
  169.                     LinkTag tag = (LinkTag) list.elementAt(y);
  170.                     if (tag.getAttributeEx("href" ) == null || tag.getAttributeEx("href" ).getValue().equals("#" )) continue; // ignore "#" href
  171.                     String href = tag.extractLink();
  172.                     try {
  173.                             URL urlFound = new URL(href);
  174.                             // tous les url des pages externes au site
  175.                             if (!urlFound.getHost().equalsIgnoreCase(url.getHost()))
  176.                             {
  177.                              System.out.println("---------------" );
  178.                               System.out.println(urlFound.getHost());
  179.                               System.out.println(url.getHost());
  180.                              System.out.println("---------------" );
  181.                              System.out.println("******---------------*******" );
  182.                              System.out.println(URLp.contains(urlFound));
  183.                                  System.out.println("******---------------******" );
  184.                              // Si la page a été déja crée Alors modifier le compteur nombre de liens entrants
  185.                               if (URLp.contains(urlFound))
  186.                               {
  187.                                  // parcourir la liste pour recupérer la page
  188.                                 for (Enumeration e = liste_page.elements() ; e.hasMoreElements() ;)
  189.                                 {
  190.                                   page1 pp = (page1) e.nextElement();
  191.                                   if (pp.get_url().equalsIgnoreCase(urlFound.toString()))
  192.                                   {
  193.                                     System.out.println("************ Modification ********" );
  194.                                     System.out.println(pp.get_url());
  195.                                    // modifier la page et la remplacer dans la liste
  196.                                     liste_page.remove(pp);
  197.                                     pp.set_n_liens(pp.get_nbl()+ 1);
  198.                                     liste_page.add(pp);
  199.                                     System.out.println(pp.get_nbl());
  200.                                   }
  201.                                 }
  202.                               }
  203.                               // in créer la page
  204.                               else
  205.                               {
  206.                                 page1 p2=new page1();
  207.                                 p2.initialiser(urlFound.toString(),urlFound.getHost().toString(),1);
  208.                                 URLp.add(urlFound);
  209.                                 liste_page.add(p2);
  210.                                 //liste_page_f.add(p2);
  211.                               }
  212.                             }
  213.                             if (URLVisité.get(new URL(base(urlFound))) == null)
  214.                             {
  215.                               URLaVisité.add(urlFound);
  216.                             }
  217.                                 } catch (MalformedURLException e) {
  218.                                         if (reduit && URLInvalide) System.err.println("invalid url : " + href + " " + format(list.elementAt(y).toHtml()));
  219.                                 }
  220.             }
  221.         } catch (ParserException e) {
  222.                 System.err.println(e.getLocalizedMessage());
  223.         } catch (MalformedURLException e) {}
  224.         }
  225. public HashMap get_hmp(){
  226.   return URLVisité;
  227. }
  228. public void affiche()
  229. {
  230.   System.out.println("***************** les pages **********" );
  231.         for (Enumeration e = liste_page.elements() ; e.hasMoreElements() ;)
  232.                                         { page1 pp = (page1) e.nextElement();
  233.                                           System.out.println(pp.get_url());
  234.                                           System.out.println(pp.get_nbl());
  235.                                         }
  236.        System.out.println("***************** les pages **********" );
  237. }
  238.     public static void main(String[] args) {
  239.         // TODO code application logic here
  240.        HtmlParser doc=new HtmlParser("http://www.siteduzero.com/" );
  241.         doc.run();
  242.    
  243.      
  244.     }
  245. }


il n'ya aucun signal d'erreur, mais dés que j'essaye d'executer voila ce qi'il m'affiche:
 
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - not a statement
        at htmlparser.HtmlParser.<init>(HtmlParser.java:83)
        at htmlparser.HtmlParser.main(HtmlParser.java:265)
 
 
SVP,quelqu'un d'entre vous aurait-il la solution? j'en ai vraiment bezoin!
merci

mood
Publicité
Posté le 11-05-2009 à 17:52:41  profilanswer
 

n°1883487
billgatesa​nonym
Posté le 11-05-2009 à 23:41:36  profilanswer
 

Il ne semble pas y avoir de problème au niveau des accolades, des parenthèses et des guillemets.
Peut-être qu'il n'aime pas le "e" accent aigu dans le nom de la variable URLaVisité. Peut-être que SiteInitial ne contiendrait pas quelque chose de valable.

n°1883488
miss5
Posté le 11-05-2009 à 23:52:25  profilanswer
 

SiteInitial contient "http://www.siteduzero.com/"

n°1883571
jufeel
Posté le 12-05-2009 à 09:59:32  profilanswer
 

Pour que l'on soit capable de t'aider plus facilement il faudrait que ta classe soit claire:
- indente un peu mieux ton code
- sois cohérente dans ton "nommage" de variables, soit en anglais ou en francais mais pas les deux, en Java les variables commence généralement par une minuscule sinon "URLaVisité.add(SiteInitial)" laisse penser que tu appelles une méthode statique de la classe URLaVisité
- évite les accents et les charactères non-ASCII dans les noms de variables et méthodes
 
Les coding coventions de SUN ne sont pas trop mal : http://java.sun.com/docs/codeconv/
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  erreur "not a statement" en java

 

Sujets relatifs
conflits entre 2 scripts javaMon site marque cette erreur lors de l ouverture
[Java] Pas de repositionnement de mes JLabel sur mon JPanel ?Passage de données de flash à php via un LoadVars : erreur en local
mysql et c++ sous codeblocks erreur o niveau de insert[Hibernate] erreur accès à la base (après un jour)
[JAVA] Définir une image de fond pour un JPanel[ksh ou bash] Erreur avec sed
[JAVA] FTPFile et accentspoo en JAVA
Plus de sujets relatifs à : erreur "not a statement" en java


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR