To quebrando a minha cabeça aqui. Tenho uma interface LogFileTailerListener que consigo compilar normalmente. Também tenho uma classe LogFileTailer cujo um dos métodos faz um referência a interface LogFileTailerListener:
Quando tento compilar a classe LogFileTailer, aparece o seguinte erro:
LogFileTailer.java:67: cannot find symbol
symbol : class LogFileTailerListener
location: class com.javasrc.tuning.agent.logfile.LogFileTailer
public void addLogFileTailerListener( LogFileTailerListener l )
Bem, pelo o que eu entendi, ele não reconhece a interface LogFileTailerListener, mas ela já está compilada e está na mesma pasta do arquivo LogFileTailer.java. Por que está dando esse erro?
packagecom.javasrc.tuning.agent.logfile;/** * Provides listener notification methods when a tailed log file is updated */publicinterfaceLogFileTailerListener{/** * A new line has been added to the tailed log file * * @param line The new line that has been added to the tailed log file */publicvoidnewLogFileLine(Stringline);}
Código da classe LogFileTailer:
packagecom.javasrc.tuning.agent.logfile;importjava.io.*;importjava.util.*;/** * A log file tailer is designed to monitor a log file and send notifications * when new lines are added to the log file. This class has a notification * strategy similar to a SAX parser: implement the LogFileTailerListener interface, * create a LogFileTailer to tail your log file, add yourself as a listener, and * start the LogFileTailer. It is your job to interpret the results, build meaningful * sets of data, etc. This tailer simply fires notifications containing new log file lines, * one at a time. */publicclassLogFileTailerextendsThread{/** * How frequently to check for file changes; defaults to 5 seconds */privatelongsampleInterval=5000;/** * The log file to tail */privateFilelogfile;/** * Defines whether the log file tailer should include the entire contents * of the exising log file or tail from the end of the file when the tailer starts */privatebooleanstartAtBeginning=false;/** * Is the tailer currently tailing? */privatebooleantailing=false;/** * Set of listeners */privateSetlisteners=newHashSet();/** * Creates a new log file tailer that tails an existing file and checks the file for * updates every 5000ms */publicLogFileTailer(Filefile){this.logfile=file;}/** * Creates a new log file tailer * * @param file The file to tail * @param sampleInterval How often to check for updates to the log file (default = 5000ms) * @param startAtBeginning Should the tailer simply tail or should it process the entire * file and continue tailing (true) or simply start tailing from the * end of the file */publicLogFileTailer(Filefile,longsampleInterval,booleanstartAtBeginning){this.logfile=file;this.sampleInterval=sampleInterval;}publicvoidaddLogFileTailerListener(LogFileTailerListenerl){this.listeners.add(l);}publicvoidremoveLogFileTailerListener(LogFileTailerListenerl){this.listeners.remove(l);}protectedvoidfireNewLogFileLine(Stringline){for(Iteratori=this.listeners.iterator();i.hasNext();){LogFileTailerListenerl=(LogFileTailerListener)i.next();l.newLogFileLine(line);}}publicvoidstopTailing(){this.tailing=false;}publicvoidrun(){// The file pointer keeps track of where we are in the filelongfilePointer=0;// Determine start pointif(this.startAtBeginning){filePointer=0;}else{filePointer=this.logfile.length();}try{// Start tailingthis.tailing=true;RandomAccessFilefile=newRandomAccessFile(logfile,"r");while(this.tailing){try{// Compare the length of the file to the file pointerlongfileLength=this.logfile.length();if(fileLength<filePointer){// Log file must have been rotated or deleted; // reopen the file and reset the file pointerfile=newRandomAccessFile(logfile,"r");filePointer=0;}if(fileLength>filePointer){// There is data to readfile.seek(filePointer);Stringline=file.readLine();while(line!=null){this.fireNewLogFileLine(line);line=file.readLine();}filePointer=file.getFilePointer();}// Sleep for the specified intervalsleep(this.sampleInterval);}catch(Exceptione){}}// Close the file that we are tailingfile.close();}catch(Exceptione){e.printStackTrace();}}}
G
gugarthur
Pessoal,
Meu problema é que não tinha criado ainda a variável CLASSPATH. Depois que a criei, deu certo.