为什么我的代码不能编译?

时间:2016-09-18 00:54:11

标签: java

我正在试图弄清楚为什么这段代码没有正确编译。当我尝试编译时,我得到它需要一个main的错误,当我添加main时,它会导致更多的错误,我真的不知道如何修复。有人可以看看代码并帮助我吗?如果有人可以提供帮助,将不胜感激。

void create(list<int*> listNodes){
    test(&listNodes);
    for(list<int*>::const_iterator it=listNodes.begin();
     it!=listNodes.end(); it++){
        int *show=*it;
        cout << *show << '\n';
    }
}

}

我为事先没有包含错误而道歉。通过cmd编译时出现以下错误。

错误:在类Polygon中找不到主方法,请将main方法定义为:public static void main(String [] args) 或者JavaFX应用程序类必须扩展javafx.application.Application

2 个答案:

答案 0 :(得分:0)

在同一个包中创建一个名为Main的单独类。在那里添加主要方法。然后实例化一个对象。

public class Main {

    public static void main(String[] args) {

        Polygon p = new Polygon();
        double apothem = p.getApothem();
        System.out.println(apothem);
    }
}

答案 1 :(得分:0)

您的代码编译得很好。你缺少的是使用你刚刚创建的对象类的另一个类。

所以基本上你需要做的就是去你的编辑器(eclipse,notepad ++等),制作另一个文件并使用这样的东西:

public class PolygonMain {

    public static void main(String[] args) {

       Polygon p = new Polygon();

       Here you can use your getters/setters toString etc. 
       The name of the object you've created in this example would be p, therefore
        p.toString() would return the toString method of your object class


    }

}