【发布时间】:2014-03-08 19:10:05
【问题描述】:
我在我实现的方法上遇到了找不到符号错误,但拼写和参数正是它们应该是的。怎么回事?
我正在尝试实现的方法:
public static Comparable[] heapify(Comparable[] array){
int index = array.length - 1;
Comparable temp;
if (index == 1){
return array;
}
else{
for (int i = index; i >= 0; i++){
while(array[i/2] != null && array[i/2].compareTo(array[i]) > 0){
temp = array[i];
array[i] = array[i/2];
array[i/2] = temp;
index = index/2;
}
}
}
}
实现该方法的测试程序:
Comparable[] array = {2,5,8,12,10,6,4};
Heap heapified = heapify(array);
heapified.printHeap();
编辑:添加编译器错误
G:\Labs\Lab_10>javac Test.java
Test.java:19: error: cannot find symbol
Heap heapified = heapify(array);
^
symbol: method heapify(Comparable[])
location: class Test
Note: .\Heap.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
【问题讨论】:
-
请提供准确编译错误+编译器指示的相关行
-
您是否导入实现
heapify()的类?另外请注意,该方法返回的是Comparable[],而不是Heap。 -
主要方法是我调用它的地方。并且这两个类在同一个文件夹中。测试程序正在调用与 heapify 相同的类中的其他方法,没有问题。并感谢您指出那堆东西。
-
你说的是两个班?那么您可能应该以
ClassName.heapify()的身份访问它,而不仅仅是heapify()。 -
哎呀,我知道这会是那样的愚蠢。我已经有一段时间没有写代码了,我总是忘记这样的小事。
标签: java compiler-construction compilation