package rectangle;import com.sun.istack.internal.logging.Logger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;/**
 *
 * @author Administrator
 */
public class Rectangle {    /**
     * @param args the command line arguments
     */
    private double length;
    private double width;    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }    private Rectangle() {
  
    }    public double getLength() {
        return length;
    }    public void setLength(double length) {
        this.length = length;
    }    public double getWidth() {
        return width;
    }    public void setWidth(double width) {
        this.width = width;
    }
    public double perimeter(){
        return 2*(length+width);
    }
    public double area(){
        return length*width;
    }
            
    
    public static void main(String[] args) {
        // TODO code application logic here
        Rectangle circle=new Rectangle();
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        try{
        System.out.println("请输入矩形的长");
        circle.setLength(Double.parseDouble(reader.readLine()));
        System.out.println("请输入矩形的宽");
        circle.setWidth(Double.parseDouble(reader.readLine()));
        System.out.println("周长="+circle.perimeter());
        System.out.println("面积="+circle.area());
    }catch(IOException ex){
    Logger.getLogger(Rectangle.class.getLength()).log(Level.SEVERE,null,ex);  
    }
}
}

解决方案 »

  1.   

    Rectangle.class.getLength()应该是对象的getLength()吧?不应该是类的getLength()
      

  2.   

    Logger.getLogger(Rectangle.class.getLength()).log(Level.SEVERE,null,ex);
    这是什么意思,不懂楼主想干啥仔细去看看Logger的用法。。
      

  3.   

    最后一行的Rectangle换成circle,就换成circle报错了
      

  4.   

    那当然,你现在的方法是在Rectangle,肯定只能用Rectangle.class,怎么可以用circle.class呢
      

  5.   

    问题是最后一行的getLength()不知道改换成什么才不会出错哈?
      

  6.   

    我这没有import com.sun.istack.internal.logging.Logger;
    我用的是import java.util.logging.Logger;
    都是日志包应该作用也差不对。
    javadoc里说:
    Parameters: name - A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem, such as java.net or javax.swing Logger.getLogger()里面的参数应该是包名或者类名
    这里你填String类型的应该是不会报错的,具体你得看需要要怎么打log了
    你可以试试Rectangle.class.getName(),就是这个类名。
      

  7.   

    支持Logger.getLogger(Rectangle.class.getName()).log(Level.SEVERE,null,ex); 
      

  8.   

    擦,才看见
    你直接circle.getLength()返回int也不符合api吧,
    虽然不知道你想记录什么,但感觉还是这个靠谱
    Logger.getLogger(Rectangle.class.getName()).log(Level.SEVERE,null,ex); 
      

  9.   


    Logger.getLogger(Rectangle.class.getLength()).log(Level.SEVERE,null,ex);   
    这个getLength()返回double估计不行吧试试这个呢?Logger.getLogger(Rectangle.class).log(Level.SEVERE,null,ex);   
      

  10.   

    //import com.sun.istack.internal.logging.Logger;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.logging.Level;/**
     *
     * @author Administrator
     */
    public class Rectangle {  /**
      * @param args the command line arguments
      */
      private double length;
      private double width;  public Rectangle(double length, double width) {
      this.length = length;
      this.width = width;
      }  private Rectangle() {
      
      }  public double getLength() {
      return length;
      }  public void setLength(double length) {
      this.length = length;
      }  public double getWidth() {
      return width;
      }  public void setWidth(double width) {
      this.width = width;
      }
      public double perimeter(){
      return 2*(length+width);
      }
      public double area(){
      return length*width;
      }
       
       
      public static void main(String[] args) {
      // TODO code application logic here
      Rectangle circle=new Rectangle();
      BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
      try{
      System.out.println("请输入矩形的长:");
      circle.setLength(Double.parseDouble(reader.readLine()));
      System.out.println("请输入矩形的宽:");
      circle.setWidth(Double.parseDouble(reader.readLine()));
      System.out.println("周长="+circle.perimeter());
      System.out.println("面积="+circle.area());
      }
      catch(IOException ex){
     // Logger.getLogger(Rectangle.class.getLength()).log(Level.SEVERE,null,ex);  
      }
    }
    }这样就能执行呀!!没有错误呀!
    static Logger global 
              已过时。 此字段的初始化会容易出现死锁。必须由 Logger 类初始化来初始化字段,这可能会导致 LogManager 类初始化的死锁。在这种情况下,两个类初始化都要等待对方完成。从 JDK version 1.6 开始,获取全局 logger 对象的首选方法是通过调用 Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)。 
    你可以查一下API文档
      

  11.   

    Logger.getLogger(Rectangle.class.getLength()).log(Level.SEVERE,null,ex);
    这样吧,这样可以知道是哪个类打印的日志比较好
    Logger.getLogger(Rectangle.class.getName()).log(Level.SEVERE,null,ex);
      

  12.   

    回复9楼的,我试过用Rectangle.class.getName(),但还是不行
      

  13.   

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package rectangle;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.logging.Level;
    import java.util.logging.Logger;/**
     *
     * @author Administrator
     */
    public class Rectangle {    /**
         * @param args the command line arguments
         */
        private double length;
        private double width;    /**
         *
         * @param length
         * @param width
         */
        public void setLength(double length) {
            this.length = length;
        }    public void setWidth(double width) {
            this.width = width;
        }
        public double perimeter(){
            return 2*(length+width);
        }
        public double area(){
            return length*width;
        }
                
        
        public static void main(String[] args) {
            // TODO code application logic here        Rectangle circle=new Rectangle();
            BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
            try{
            System.out.println("请输入矩形的长");
            circle.setLength(Double.parseDouble(reader.readLine()));
            System.out.println("请输入矩形的宽");
            circle.setWidth(Double.parseDouble(reader.readLine()));
            System.out.println("周长="+circle.perimeter());
            System.out.println("面积="+circle.area());
        }catch(IOException ex){        Logger.getLogger(Rectangle.class.getName()).log(Level.SEVERE,null,ex); 
        }
    }
    }
    正确的代码!前天只是import引入有错!谢谢你们啦!