java - 找不到符号错误,拼写错误和参数均不正确

标签 java compiler-construction compilation

我在实现的方法中遇到找不到符号错误,但拼写和参数正是它们应该的样子。这是怎么回事?

我正在尝试实现的方法:

    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

最佳答案

请提供更多信息。现在能提供的帮助太少了。

但是,我的猜测是:

  1. 方法“heapify(Comparable[])”位于不同的类中,因此您必须编写:

    Heap heapified = CLASS_WITH_HEAPIFY.heapify(array);

  2. 检查主类中的导入。也许您没有导入包含“heapify”的类的正确包

关于java - 找不到符号错误,拼写错误和参数均不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22273785/

相关文章:

java - 我如何继承 ByteBuffer?

c++ - 如果使用优化 (-O2, -O3),为什么这段代码的行为会有所不同?

language-agnostic - 识别不同语言并将它们发送到相应编译器的编译器。可能的?

c - Freeimage ANSI C Codeblock Windows - 链接 - 新手

c++ - 如何分析/优化 Objc/C++ 项目编译时间?

c - C编程报错后报错信息中的 "label"是什么?

java - java获取windows网卡 "Media State"?

java - 捕获异常后的xml解析和验证

java - 警告 : Attempt to convert JsonElement from GSON. 此功能已弃用。 Selenium 跟踪诊断堆栈跟踪

compiler-construction - 如何缓存由 Groovy 脚本引擎生成的编译类?