Search code examples
javacompilation

Cannot Find Symbol Error, No Typos and Arguments are correct


I'm getting a cannot find symbol error on a method I implemented, but the spelling and arguments are exactly what they're supposed to be. What's going on?

Method I'm trying to implement:

    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;
            }
        }
    }
}

Test program that is implementing the method:

Comparable[] array = {2,5,8,12,10,6,4};
Heap heapified = heapify(array);
heapified.printHeap();

EDIT: Added Compiler error

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

Solution

  • Please provide some more information. Right now it's too little to help.

    But, my guesses are :

    1. Method "heapify(Comparable[])" is in diffrent class so you musr write :

      Heap heapified = CLASS_WITH_HEAPIFY.heapify(array);

    2. Check your imports in main class. Maybe your not importing the right package with Class containing 'heapify'