java.lang.NoSuchMethodError: main Exception in thread "main"
Possible Duplicate:
Exception in thread “main” java.lang.NoSuchMethodError: main
My main syntax is correct. What else could be the problem?
public class BuildHeap
{
int a[]={1,2,6,3,5,1,7,8,4,9};
public void build()
{
for(int i=5;i<=1;i--)
{
heapify(a,i);
}
}
public void heapify(int a[],int i)
{
System.out.print("hello");
int j,temp,rchild,lchild;
if(i<5)
{
if(2*i<5)
lchild=a[(2*i)+1];
if((2*i)+1<4)
rchild=a[(2*i)+2];
if(lchild>rchild)
j=(2*i)+1;
else
j=(2*i)+2;
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
heapify(a,j);
} } }
class Heap
{
public static void main(String[] args)
{
BuildHeap bh=new BuildHeap();
bh.build();
for(int i=0;i<10;i++)
System.out.print(bh.a[i]+" ");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
You need to put the main method in the public class
BuildHeap
(not the package-private classHeap
). Or maybe you just specified the wrong class name on the command line. Again, main is inHeap
, notBuildHeap
.The most probable cause should be that your class name and file name doesnot match.
Create a new file containing the class Heap and have the filename as Heap.java.
Keep BuildHeap class in a different file in the same package. Run Heap. It should work.
Else change the BuildHeap class from public class and make the Heap class as public.
The better way would be to separate the classes in different files.