Cannot Find Symbol Error: Trying To Call a Method

Cannot Find Symbol Error: Trying To Call a Method

我正在为我的介绍 Java class 做作业,运行 遇到了一个我似乎无法弄清楚的错误!我必须创建一个静态 sortIntoGroups 方法来对数组进行分区而不使用任何 while 循环。该方法必须可从单独的驱动程序 class 调用。我目前正在尝试使用主要方法对其进行测试,但由于某种原因它似乎无法识别该方法。这是我的代码: public class ArrayHelper{

public class ArrayHelper{
public static int sortIntoGroups (int[] arrayToSort, int partitionValue){
    int i = 0;
    int j = (arrayToSort.length-1);
    do{
        for(i=0; i < partitionValue; i++ ){
        for(j = (arrayToSort.length-1); j > partitionValue; j--){
        if (i < j){
            int tempVar = arrayToSort[i];
                arrayToSort[i] = arrayToSort[j];
                arrayToSort[j] = tempVar;
        }//end if 
        }//end j for
        }// end i for 
    }while(i< j);

    return j;

}//end sortIntoGroups

public static void main (String [] args){
    int [] testArray = {1, 2, 3, 4, 5};
    int partitionVal = 4;

System.out.print(testArray.sortIntoGroups(testArray, partitionVal));

}
}   

有什么想法吗? 谢谢!

静态方法由 Class 名称引用。 您应该将方法调用为

   System.out.print(ArrayHelper.sortIntoGroups(testArray, partitionVal));

希望对您有所帮助:)