I've been trying for hours and I mean hours to get this to work and I keep getting this compiler error if anyone can please help me it would be greatly appreciated.
I am getting the Exception error on this line in the MyProgram class:
logger.setLevel(Level.INFO);
public abstract class SimpleLogger { protected Level level; public void setLevel(Level l){ level = l; } public Level getLevel(){ return level; } public abstract void log(Level logLevel, String component, String msg) throws LoggerException; public abstract void log(Level error, String component, Throwable t) throws LoggerException; } import java.util.*; import java.text.*; import java.io.*; public class FileLogger extends SimpleLogger { private File logFile; private int logEntryNo = 0; private static FileLogger instance = null; public FileLogger(String logFilePath){ logFile = new File(logFilePath); try{ logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } public static FileLogger getInstance(){ return instance; } public synchronized void add(String data){ DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(); String dateTime = dateFormat.format(date); try{ if (logFile.createNewFile()){ FileWriter fileWriter = new FileWriter(logFile); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write("[" + dateTime + "]#" + ++logEntryNo + ": " + data); bufferedWriter.newLine(); bufferedWriter.close(); } else{ FileWriter fileWriter = new FileWriter(logFile,true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write("[" + dateTime + "]#" + ++logEntryNo + ": " + data); bufferedWriter.newLine(); bufferedWriter.close(); } } catch (IOException e) { e.printStackTrace(); } } @Override public void log(Level logLevel, String component, String msg) throws LoggerException { // TODO Auto-generated method stub } @Override public void log(Level error, String component, Throwable t) throws LoggerException { // TODO Auto-generated method stub } } public enum Level { DEBUG(1), WARNING(2), SEVERE(3), INFO(4), ERROR(5); private int level; private Level(int level) { this.level = level; } public int getLevel(){ return level; } } public class LoggerException extends Throwable { /** * */ private static final long serialVersionUID = 1L; public LoggerException(String name){ super("No attribute named \" " + name + "\" found"); } } public class LoggerFactory { LoggerFactory factory = new LoggerFactory(); public static FileLogger getLogger(String string) { if(string.equals("file")) return new FileLogger(string); return null; } } public class MyProgram { private SimpleLogger logger; public static void main(String[] args) { try { SimpleLogger logger = LoggerFactory.getLogger("File"); logger.setLevel(Level.INFO); logger.log(Level.INFO, "main", "system starting"); try { double res1 = doDivision(2,3); double res2 = doDivision(3,0); } catch (Exception e) { logger.log(Level.ERROR, "main", e); } logger.log(Level.INFO, "main", "system ending"); } catch (LoggerException e) { e.printStackTrace(); } } private static double doDivision(int i, int j) { { double res=0; try { SimpleLogger logger = LoggerFactory.getLogger("File"); // logger.initialize(); logger.log(Level.INFO, "doDivision", "entering"); if ( j == 0) { throw new IllegalArgumentException("Attempt to divide by 0"); } else { res = i/j; logger.log(Level.INFO, "doDivision", "result is " + res); } } catch (LoggerException e) { e.printStackTrace(); } return res; } } }