【问题标题】:getting unexpected typer error in returing object array返回对象数组时出现意外类型错误
【发布时间】:2015-06-20 10:24:40
【问题描述】:

当我尝试返回对象数组时,为什么会在第 22 行出现意外类型错误?

public class StudentDemo {
public static void main(String args[]){

    StudentDemo program = new StudentDemo();
    program.start();
}

public void start(){
    Student one = new Student(1, "x", 80.0);
    Student two = new Student(2, "y", 81.0);
    Student three = new Student(3,"z", 79.5);
    Student four = new Student(4, "a", 85.0);
    Student five = new Student(5, "b", 86.0);
    Student arr[] = {one,two,three,four,five};
    Student[] splitarr = splitStudentArray(arr, char 'e'); //line 22
    splitarr[0].getName();
}

public Student[] splitStudentArray(Student arr[], char choice){

    Student[] splitArr = new Student[5];
    if(choice == 'e'){

        for(int i = 0; i<5; i++){
            if(arr[i].getMarks()%2 == 0){
                splitArr[i] = arr[i];
            }
        }
    }

    else if(choice == 'o'){

        for(int i = 0; i<5; i++){
            if(arr[i].getMarks()%2 != 0){
                splitArr[i] = arr[i];
            }
        }
    }

    return splitArr;
}
}

错误提示:

必需:找到的值:类。

请帮助我找出错误及其发生的原因。

【问题讨论】:

    标签: java arrays


    【解决方案1】:

    改变

    Student[] splitarr = splitStudentArray(arr, char 'e');
    

    Student[] splitarr = splitStudentArray(arr,'e');
    

    在调用方法时,您没有指定变量的类型(在您的情况下为 char)。

    【讨论】:

      猜你喜欢
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多