Nick Div Nick Div - 1 year ago 81
Java Question

Not able to call method "error" from the logger object.

package firstAOP;

import java.util.logging.Logger;

public class OrderDAO
private final static Logger logger = Logger.getLogger(OrderDAO.class.getName());
public boolean saveOrder(Order order)
boolean flag =false;

//functional code
flag = true;
catch(Exception e)
return flag;

In the above code I get an error in the line "logger.error(e)"
This is the error:
The method error() is undefined for the type Logger

Rest of the methods like are working.

And if it is not too much to ask can you please tell me have I declared logger correctly. And what will happen if I write:

private final static Logger logger = Logger.getLogger(SaveOrder.class.getName());

SaveOrder is another class in the same package.

Answer Source

You are using java.util.logging.Logger and this logger has no error() method.

Either use

Logger.log(Level, String);
Logger.log(Level, String, Throwable);

with one of the levels defined in java.util.logging.Level



... to your second question:

The logger is declared well.

If you change the logger declaration to

 private final static Logger logger = Logger.getLogger(SaveOrder.class.getName());

then the logger will have another name. The name is used when you configure the logging system. I would suggest you to read the Java Logging Overview and come back when you have a particular question about the java logging system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download