最后一行代码中的getLength()被提示出错,不知道是怎么回事哈?跪求高人指点
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);
}
}
}
------解决方案--------------------我这没有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(),就是这个类名。
------解决方案--------------------擦,才看见
你直接
circle.getLength()返回int也不符合api吧,
虽然不知道你想记录什么,但感觉还是这个靠谱
Logger.getLogger(Rectangle.class.getName()).log(Level.SEVERE,null,ex);