大家帮我看一下 下面这段 代码好吗?
怎么连接时 有 Exception in thread "main" java.lang.NoSuchMethodError:main
的错误呢? 我一直都找不到原因,各位大虾 帮我看一下 好吗? 谢谢!
public interface ConversionFators{
double INCH_TO_MM = 25.4;
double OUNCE_TO_GRAM = 28.349;
double POUND_TO_GRAM = 453.59;
double HP_TO_WATT = 745.7;
double WATT_TO_HP = 1.0/HP_TO_WATT;
}
interface Shape{
void draw();
void print();
}
class Point{
int x,y;
Point(int x, int y){
this.x = x;
this.y = y;
}
void moveTo(int newx, int newy){
x = newx; y = newy;
}
public String toString(){
return(x+" "+y);
}
class Circle implements Shape{
Point center;
int radius;
Circle(){
this(0,0,0);
}
Circle(int x, int y, int size){
center = new Point(x,y);
radius = size;
}
public void draw(){
System.out.println("Drawing a Circle of radius"+radius+"at"+center);
}
public void print(){
System.out.println("Circle("+center+" "+radius+")");
}
public void main(String[] args){
Shape s[] = new Shape[3];
for(int i = 0; i < 3; i++)
{ s[i] = new Circle(i,i,i);}
for(int i = 0; i < 3; i++)
{ s[i].print(); }
}
}
}
怎么连接时 有 Exception in thread "main" java.lang.NoSuchMethodError:main
的错误呢? 我一直都找不到原因,各位大虾 帮我看一下 好吗? 谢谢!
public interface ConversionFators{
double INCH_TO_MM = 25.4;
double OUNCE_TO_GRAM = 28.349;
double POUND_TO_GRAM = 453.59;
double HP_TO_WATT = 745.7;
double WATT_TO_HP = 1.0/HP_TO_WATT;
}
interface Shape{
void draw();
void print();
}
class Point{
int x,y;
Point(int x, int y){
this.x = x;
this.y = y;
}
void moveTo(int newx, int newy){
x = newx; y = newy;
}
public String toString(){
return(x+" "+y);
}
class Circle implements Shape{
Point center;
int radius;
Circle(){
this(0,0,0);
}
Circle(int x, int y, int size){
center = new Point(x,y);
radius = size;
}
public void draw(){
System.out.println("Drawing a Circle of radius"+radius+"at"+center);
}
public void print(){
System.out.println("Circle("+center+" "+radius+")");
}
public void main(String[] args){
Shape s[] = new Shape[3];
for(int i = 0; i < 3; i++)
{ s[i] = new Circle(i,i,i);}
for(int i = 0; i < 3; i++)
{ s[i].print(); }
}
}
}
public static void main(String[] args){}
可能是这个原因。
the method main cannot be declared static, static method can only be declared in a static or top level type;
你拿eclipse跑下,会发现它让你找"main"
但是 这个小程序结构 已经完了,怎么才 可以 有main的入口函数呢
这只是第一点,第二点就是,你的main方法在一个内部类中,你没看到吗?????
class Point{
int x,y;
Point(int x, int y){
this.x = x;
this.y = y;
}
void moveTo(int newx, int newy){
x = newx; y = newy;
}
public String toString(){
return(x+" "+y);
}
}public class Circle implements Shape{
Point center;
int radius;
Circle(){
this(0,0,0);
}
Circle(int x, int y, int size){
center = new Point(x,y);
radius = size;
}
public void draw(){
System.out.println("Drawing a Circle of radius"+radius+"at"+center);
}
public void print(){
System.out.println("Circle("+center+" "+radius+")");
}
public static void main(String[] args){
Shape s[] = new Shape[3];
for(int i = 0; i < 3; i++)
{ s[i] = new Circle(i,i,i);}
for(int i = 0; i < 3; i++)
{ s[i].print(); }
}
} 这样就没问题了.你试试
但是我 不知道怎么来修改这个问题 ,呵呵!
谢谢你!