错误信息说明在Java中 [英] Error Message Help in Java

查看:111
本文介绍了错误信息说明在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是应该在员工工时,存储在一个二维数组文件,打印的二维数组,然后打印总时间为每个员工一个文件中读取一个程序。这是一种模糊的,我知道,但我的问题是多与我不断收到这条错误消息,比它与程序本身。这里是code我有

I am working on a program that is supposed to read in a file of employee hours, store that file in a 2D array, print that 2D array, then print the total hours for each employee. That's kind of vague, I know, but my problem is more with this one error message I keep getting, than it is with the program itself. Here is the code I have

import java.util.Scanner;

public class Program2 {
    public static void main(String[] args) {
        int employeeNum;
        int i;
        int j;
        int empId;
        int days;
        int[][] hoursArray = new int[employeeNum][7];
        int[] totalHours = new int[hoursArray.length];
        int[] indexList = new int[totalHours.length];

        java.io.File file = new java.io.File("../instr/prog2.dat");
        Scanner fin = new Scanner(file);
             employeeNum = fin.nextInt();
                for(empId = 0; empId < employeeNum;
                empId++)
                    for(days = 0; days < 7; days++)
                        hoursArray[empId][days] = fin.nextInt();
        System.out.println(hoursArray[empId][days]);

        for(i = 0; i < hoursArray.length; i++)          for(j = 0; j < hoursArray[i].length; j++)
                totalHours[i] += hoursArray[i][j];

        sortIndex(totalHours.length, indexList);

        for (int index = totalHours.length - 1; index >= 0; index--)
                System.out.println("Employee " + indexList[index] + ": "
            + totalHours[index]);
    }

    static void sortIndex(int[] list, int[] indexList) {
        int max;
        int maxIndex;
        int i;
        int j; 
        for(i = 0; i < indexList.length; i++)
            indexList[i] = i;

        for(i = list.length - 1; i >= 1; i--) {
            max = list[i];
            maxIndex = i;

          for(j = i - 1; j >= 0; j--)
                    if(max < list[j]) {
                    max = list[j];
                    maxIndex = j;
                }
            }

        if(maxIndex != i) {
            list[maxIndex] = list[i];
            list[i] = max;

            int temp = indexList[i];
            indexList[i] = indexList[maxIndex];
            indexList[maxIndex] = temp;
        }
    }
 }

我不断收到错误消息:

I keep getting the error message :

的方法sortIndex(INT [],INT [])在类型PROG2不适用的参数(INT,INT [])

在code的这一部分:

at this portion of code :

sortIndex(totalHours.length, indexList);

我从来没有碰到过这样的错误之前,而且不知道如何解决它。这个特定的任务是在其中具有用于它编写的程序书的变型,但在书的问题不会文件处理。我们的教授说,这应该是简单的,因为我们基本上可以在这本书中键入了确切的程序只写code从文件输入读取。于是,我与有问题的code的这一部分是直接从本书,所以我不知道我应该怎么做来解决它。请帮忙。

I've never come across this error before and have no idea how to fix it. This particular assignment was a variation of one in the book which has a program written for it, but the problem in the book doesn't deal with files. Our professor said this should be simple since we can basically type out the exact program in the book only writing code to read in the input from a file. So this portion of the code that I am having the problem with is straight from the book, so I have no idea what I'm supposed to do to fix it. Please help.

推荐答案

该错误是自我解释:

该方法无效sortIndex(INT []列表,INT [] indexList)需要两个一维数组作为输入,但同时称这是您要发送的第一个参数为totalHours。长度是所述阵列的长度和一个int值,而不是一个INT 1D阵列

The method void sortIndex(int[] list, int[] indexList) need two 1D array as input but while calling it you are sending the first argument as totalHours.length which is the length of the array and a int value and not a int 1D array.

sortIndex(totalHours.length, indexList);

好像你需要调用:

It seems like you need to call :

   sortIndex(totalHours, indexList);

作为totalHours是一维数组。

as totalHours is a 1D array.

这篇关于错误信息说明在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆