IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

code java qui ne compile pas


Sujet :

avec Java

  1. #1
    Membre habitué
    Inscrit en
    Janvier 2004
    Messages
    532
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 532
    Points : 144
    Points
    144
    Par défaut code java qui ne compile pas
    Salut,

    J'ai telecharger un code sur le net
    quand je veux le compiler avec eclipse,
    je fais run
    la boite de dialogue apparait avec deux lignes
    sur chaque ligne il y a une espece de fourmi grise devant et ecris apres Ant Build

    quand je selectionne une ligne et que je clique sur OK
    une boite de dialogue apparait avec :

    Build Failed

    Reason :
    Unable to find an Ant file to run.
    comment cela se fait il ?et qu'est ce que sa signifie

    merci de votre aide

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    42
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 42
    Points : 41
    Points
    41
    Par défaut
    Salut,

    Manifestement, tu sembles avoir essayé de lancer un script Ant. Comment as-tu lancé ton programme ?

  3. #3
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    le code que tu as récupéré est un jar, un zip, une simple classe?
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

  4. #4
    Membre habitué
    Inscrit en
    Janvier 2004
    Messages
    532
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 532
    Points : 144
    Points
    144
    Par défaut
    en faite c est un code que j'ai recuprer sur le site de sun,
    je l'ai enregistrer sur mon pc et c'etait un .java;
    je l'ai ouvert avec eclipse et j'ai compiler

  5. #5
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    pourquoi ne pas le compiler a la main par la console?
    sinon par eclipse fais un clic droit sur le projet ->Rus As -> Java Application
    il ne devrait pas y avoir de problème!
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

  6. #6
    Membre habitué
    Inscrit en
    Janvier 2004
    Messages
    532
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 532
    Points : 144
    Points
    144
    Par défaut
    j'ai essayer de le compiler a la main
    en faisant javac et j'ai ceci
    WebCrawler.java:16: reference to List is ambiguous, both class java.util.List in
    java.util and class java.awt.List in java.awt match
    List listMatches;
    ^
    WebCrawler.java:76: reference to List is ambiguous, both class java.util.List in
    java.util and class java.awt.List in java.awt match
    listMatches = new List(10);
    ^
    Note: WebCrawler.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: WebCrawler.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors


    voila le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    import java.applet.Applet;
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
     
    public class WebCrawler extends Applet implements ActionListener, Runnable {
        public static final String SEARCH = "Search";
        public static final String STOP = "Stop";
        public static final String DISALLOW = "Disallow:";
        public static final int    SEARCH_LIMIT = 50;
     
        Panel   panelMain;
        List    listMatches;
        Label   labelStatus;
     
        // URLs to be searched
        Vector vectorToSearch;
        // URLs already searched
        Vector vectorSearched;
        // URLs which match
        Vector vectorMatches;
     
        Thread searchThread;
     
        TextField textURL;
        Choice    choiceType;
     
        public void init() {
     
    	// set up the main UI panel
    	panelMain = new Panel();
    	panelMain.setLayout(new BorderLayout(5, 5));
     
    	// text entry components
    	Panel panelEntry = new Panel();
    	panelEntry.setLayout(new BorderLayout(5, 5));
     
    	Panel panelURL = new Panel();
    	panelURL.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    	Label labelURL = new Label("Starting URL: ", Label.RIGHT);
    	panelURL.add(labelURL);
    	textURL = new TextField("", 40);
    	panelURL.add(textURL);
    	panelEntry.add("North", panelURL);
     
    	Panel panelType = new Panel();
    	panelType.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    	Label labelType = new Label("Content type: ", Label.RIGHT);
    	panelType.add(labelType);
    	choiceType = new Choice();
    	choiceType.addItem("text/html");
    	choiceType.addItem("audio/basic");
    	choiceType.addItem("audio/au");
    	choiceType.addItem("audio/aiff");
    	choiceType.addItem("audio/wav");
    	choiceType.addItem("video/mpeg");
    	choiceType.addItem("video/x-avi");
    	panelType.add(choiceType);
    	panelEntry.add("South", panelType);
     
    	panelMain.add("North", panelEntry);
     
    	// list of result URLs
    	Panel panelListButtons = new Panel();
    	panelListButtons.setLayout(new BorderLayout(5, 5));
     
    	Panel panelList = new Panel();
    	panelList.setLayout(new BorderLayout(5, 5));
    	Label labelResults = new Label("Search results");
    	panelList.add("North", labelResults);
    	Panel panelListCurrent = new Panel();
    	panelListCurrent.setLayout(new BorderLayout(5, 5));
    	listMatches = new List(10);
    	panelListCurrent.add("North", listMatches);
    	labelStatus = new Label("");
    	panelListCurrent.add("South", labelStatus);
    	panelList.add("South", panelListCurrent);
     
    	panelListButtons.add("North", panelList);
     
    	// control buttons
    	Panel panelButtons = new Panel();
    	Button buttonSearch = new Button(SEARCH);
    	buttonSearch.addActionListener(this);
    	panelButtons.add(buttonSearch);
    	Button buttonStop = new Button(STOP);
    	buttonStop.addActionListener(this);
    	panelButtons.add(buttonStop);
     
    	panelListButtons.add("South", panelButtons);
     
    	panelMain.add("South", panelListButtons);
     
    	add(panelMain);
    	setVisible(true);
     
    	repaint(); 
     
    	// initialize search data structures
    	vectorToSearch = new Vector();
    	vectorSearched = new Vector();
    	vectorMatches = new Vector();
     
    	// set default for URL access
    	URLConnection.setDefaultAllowUserInteraction(false);
        }
     
        public void start() {
        }
     
        public void stop() {
    	if (searchThread != null) {
    	    setStatus("stopping...");
    	    searchThread = null;
    	}
        }
     
        public void destroy() {
        }
     
        boolean robotSafe(URL url) {
    	String strHost = url.getHost();
     
    	// form URL of the robots.txt file
    	String strRobot = "http://" + strHost + "/robots.txt";
    	URL urlRobot;
    	try { 
    	    urlRobot = new URL(strRobot);
    	} catch (MalformedURLException e) {
    	    // something weird is happening, so don't trust it
    	    return false;
    	}
     
    	String strCommands;
    	try {
    	    InputStream urlRobotStream = urlRobot.openStream();
     
    	    // read in entire file
    	    byte b[] = new byte[1000];
    	    int numRead = urlRobotStream.read(b);
    	    strCommands = new String(b, 0, numRead);
    	    while (numRead != -1) {
    		if (Thread.currentThread() != searchThread)
    		    break;
    		numRead = urlRobotStream.read(b);
    		if (numRead != -1) {
    		    String newCommands = new String(b, 0, numRead);
    		    strCommands += newCommands;
    		}
    	    }
    	    urlRobotStream.close();
    	} catch (IOException e) {
    	    // if there is no robots.txt file, it is OK to search
    	    return true;
    	}
     
    	// assume that this robots.txt refers to us and 
    	// search for "Disallow:" commands.
    	String strURL = url.getFile();
    	int index = 0;
    	while ((index = strCommands.indexOf(DISALLOW, index)) != -1) {
    	    index += DISALLOW.length();
    	    String strPath = strCommands.substring(index);
    	    StringTokenizer st = new StringTokenizer(strPath);
     
    	    if (!st.hasMoreTokens())
    		break;
     
    	    String strBadPath = st.nextToken();
     
    	    // if the URL starts with a disallowed path, it is not safe
    	    if (strURL.indexOf(strBadPath) == 0)
    		return false;
    	}
     
    	return true;
        }
     
        public void paint(Graphics g) {
          	//Draw a Rectangle around the applet's display area.
          	g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
     
    	panelMain.paint(g);
    	panelMain.paintComponents(g);
    	// update(g);
    	// panelMain.update(g);
        }
     
        public void run() {
    	String strURL = textURL.getText();
    	String strTargetType = choiceType.getSelectedItem();
    	int numberSearched = 0;
    	int numberFound = 0;
     
    	if (strURL.length() == 0) {
    	    setStatus("ERROR: must enter a starting URL");
    	    return;
    	}
     
    	// initialize search data structures
    	vectorToSearch.removeAllElements();
    	vectorSearched.removeAllElements();
    	vectorMatches.removeAllElements();
    	listMatches.removeAll();
     
    	vectorToSearch.addElement(strURL);
     
    	while ((vectorToSearch.size() > 0) 
    	  && (Thread.currentThread() == searchThread)) {
    	    // get the first element from the to be searched list
    	    strURL = (String) vectorToSearch.elementAt(0);
     
    	    setStatus("searching " + strURL);
     
    	    URL url;
    	    try { 
    		url = new URL(strURL);
    	    } catch (MalformedURLException e) {
    		setStatus("ERROR: invalid URL " + strURL);
    		break;
    	    }
     
    	    // mark the URL as searched (we want this one way or the other)
    	    vectorToSearch.removeElementAt(0);
    	    vectorSearched.addElement(strURL);
     
    	    // can only search http: protocol URLs
    	    if (url.getProtocol().compareTo("http") != 0) 
    		break;
     
    	    // test to make sure it is before searching
    	    if (!robotSafe(url))
    		break;
     
    	    try {
    		// try opening the URL
    		URLConnection urlConnection = url.openConnection();
     
    		urlConnection.setAllowUserInteraction(false);
     
    		InputStream urlStream = url.openStream();
    		String type 
    		  = urlConnection.guessContentTypeFromStream(urlStream);
    		if (type == null)
    		    break;
    		if (type.compareTo("text/html") != 0) 
    		    break;
     
    		// search the input stream for links
    		// first, read in the entire URL
    		byte b[] = new byte[1000];
    		int numRead = urlStream.read(b);
    		String content = new String(b, 0, numRead);
    		while (numRead != -1) {
    		    if (Thread.currentThread() != searchThread)
    			break;
    		    numRead = urlStream.read(b);
    		    if (numRead != -1) {
    			String newContent = new String(b, 0, numRead);
    			content += newContent;
    		    }
    		}
    		urlStream.close();
     
    		if (Thread.currentThread() != searchThread)
    		    break;
     
    		String lowerCaseContent = content.toLowerCase();
     
    		int index = 0;
    		while ((index = lowerCaseContent.indexOf("<a", index)) != -1)
    		{
    		    if ((index = lowerCaseContent.indexOf("href", index)) == -1) 
    			break;
    		    if ((index = lowerCaseContent.indexOf("=", index)) == -1) 
    			break;
     
    		    if (Thread.currentThread() != searchThread)
    			break;
     
    		    index++;
    		    String remaining = content.substring(index);
     
    		    StringTokenizer st 
    		      = new StringTokenizer(remaining, "\t\n\r\">#");
    		    String strLink = st.nextToken();
     
    		    URL urlLink;
    		    try {
    			urlLink = new URL(url, strLink);
    			strLink = urlLink.toString();
    		    } catch (MalformedURLException e) {
    			setStatus("ERROR: bad URL " + strLink);
    			continue;
    		    }
     
    		    // only look at http links
    		    if (urlLink.getProtocol().compareTo("http") != 0)
    			break;
     
    		    if (Thread.currentThread() != searchThread)
    			break;
     
    		    try {
    			// try opening the URL
    			URLConnection urlLinkConnection 
    			  = urlLink.openConnection();
    			urlLinkConnection.setAllowUserInteraction(false);
    			InputStream linkStream = urlLink.openStream();
    			String strType 
    			  = urlLinkConnection.guessContentTypeFromStream(linkStream);
    			linkStream.close();
     
    			// if another page, add to the end of search list
    			if (strType == null)
    			    break;
    			if (strType.compareTo("text/html") == 0) {
    			    // check to see if this URL has already been 
    			    // searched or is going to be searched
    			    if ((!vectorSearched.contains(strLink)) 
    			      && (!vectorToSearch.contains(strLink))) {
     
    				// test to make sure it is robot-safe!
    				if (robotSafe(urlLink))
    				    vectorToSearch.addElement(strLink);
    			    }
    			}
     
    			// if the proper type, add it to the results list
    			// unless we have already seen it
    			if (strType.compareTo(strTargetType) == 0) {
    			    if (vectorMatches.contains(strLink) == false) {
    				listMatches.add(strLink);
    				vectorMatches.addElement(strLink);
    				numberFound++;
    				if (numberFound >= SEARCH_LIMIT)
    				    break;
    			    }
    			}
    		    } catch (IOException e) {
    			setStatus("ERROR: couldn't open URL " + strLink);
    			continue;
    		    }
    		}
    	    } catch (IOException e) {
    		setStatus("ERROR: couldn't open URL " + strURL);
    		break;
    	    }
     
    	    numberSearched++;
    	    if (numberSearched >= SEARCH_LIMIT)
    		break;
    	}
     
    	if (numberSearched >= SEARCH_LIMIT || numberFound >= SEARCH_LIMIT)
    	    setStatus("reached search limit of " + SEARCH_LIMIT);
    	else
    	    setStatus("done");
    	searchThread = null;
    	// searchThread.stop();
        }
     
        void setStatus(String status) {
    	labelStatus.setText(status);
        }
     
        public void actionPerformed(ActionEvent event) {
    	String command = event.getActionCommand();
     
    	if (command.compareTo(SEARCH) == 0) {
    	    setStatus("searching...");
     
    	    // launch a thread to do the search
    	    if (searchThread == null) {
    		searchThread = new Thread(this);
    	    }
    	    searchThread.start();
    	}
    	else if (command.compareTo(STOP) == 0) {
    	    stop();
    	}
        }
            public static void main (String argv[])
            {
                    Frame f = new Frame("WebFrame");
                    WebCrawler applet = new WebCrawler();
    		f.add("Center", applet);
     
    /*		Behind a firewall set your proxy and port here!
    */
                    Properties props= new Properties(System.getProperties());
                    props.put("http.proxySet", "true");
            	props.put("http.proxyHost", "webcache-cup");
            	props.put("http.proxyPort", "8080");
     
                    Properties newprops = new Properties(props);
                    System.setProperties(newprops);
    /**/
     
     
                    applet.init();
                    applet.start();
                    f.pack();
                    f.show();
            }
     
    }

  7. #7
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    importe java.awt.List !
    il ne sait pas quoi utiliser entre la liste de awt et la liste de java.util

    ou alors mets ça
    java.awt.List listMatches;
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

  8. #8
    Membre habitué
    Inscrit en
    Janvier 2004
    Messages
    532
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 532
    Points : 144
    Points
    144
    Par défaut
    j'ai rajouter cela
    import java.awt.*;

    mais ça donne rien

  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    731
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 731
    Points : 574
    Points
    574
    Par défaut
    Essaie de modifier tes imports de la sorte :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.Choice;
    import java.awt.FlowLayout;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Label;
    import java.awt.List;
    import java.awt.Panel;
    import java.awt.TextField;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Properties;
    import java.util.StringTokenizer;
    import java.util.Vector;

  10. #10
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    ou a ta ligne 16 mets java.awt.List
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

Discussions similaires

  1. Code qui ne compile pas
    Par zsoufianz dans le forum Débuter avec Java
    Réponses: 4
    Dernier message: 04/12/2014, 21h17
  2. Code de connexion qui ne compile pas
    Par sousou_ dans le forum JDBC
    Réponses: 5
    Dernier message: 05/10/2014, 13h32
  3. Code Java qui ne compile pas
    Par bawilar dans le forum Débuter avec Java
    Réponses: 2
    Dernier message: 03/11/2009, 09h25
  4. code qui se compile pas
    Par zangaloni dans le forum Interfaces Graphiques en Java
    Réponses: 4
    Dernier message: 26/04/2009, 16h53
  5. un code qui ne compile pas
    Par muslim1987 dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 19/06/2008, 11h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo