Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ArrayList数组类型不匹配_Java_Arraylist_Jgrasp - Fatal编程技术网

Java ArrayList数组类型不匹配

Java ArrayList数组类型不匹配,java,arraylist,jgrasp,Java,Arraylist,Jgrasp,我正在尝试(对于一个学校实验室)创建一个程序,现在只需在数组中显示项目(我们使用JGrasp作为IDE,这是一个必需的部分,因为它需要它制作的项目)。它需要五个类:Employee的超类、定义员工类型的两个子类、测试方法(UseCompany)和FileIO类 import java.util.*; public class UseCompany { public static void main(String[] args) { System.out.print("H

我正在尝试(对于一个学校实验室)创建一个程序,现在只需在数组中显示项目(我们使用JGrasp作为IDE,这是一个必需的部分,因为它需要它制作的项目)。它需要五个类:Employee的超类、定义员工类型的两个子类、测试方法(UseCompany)和FileIO类

import java.util.*;

public class UseCompany {
    public static void main(String[] args) {
        System.out.print("Hello");
        SalesMan man1 = new SalesMan("John Doe", 12345);
        Technician tech1 = new Technician("Jane Doe", 12346);
        ArrayList<Employee> company = new ArrayList<Employee>();
        company.add(man1);
        company.add(tech1);
        SalesMan man2 = new SalesMan(1500.00, "Steelport", "Johnny Gat", 14432);
        Technician tech2 = new Technician(5, "IT Support", "Kinzie Kensington", 10000);
        company.add(man2);
        company.add(tech2);
        Collections.sort(company);
        ArrayList<Employee> temp = company;
        FileIO.displayArray(temp); //Line 19, the problem point.
    }
}
仅供参考:技术人员添加私有int级别、私有字符串部门、getter和toString 销售人员添加私有双目标、私有字符串区域、getter和toString

编辑: 出于某种原因,即使从displayArray方法的调用和实现中删除了所有参数,并注释掉了其全部内容,它似乎仍需要ArrayList[]类型的数据,将错误指向FileIO和displayArray()之间的点

最终编辑: 谢谢你,费尔多。事实证明,删除项目文件并重新制作它才是解决方案。现在一切都好了。
我希望我或我的老师昨晚在实验室里弄明白了这一点。

回答而不是评论:

jGrasp似乎在运行时使用了一些过时的类文件。由于我对IDE缺乏了解,所以我不知道如何进行,但我建议对编译后的类进行彻底清理


我还建议你写下自己的答案,描述你是如何消除这个错误并接受这个错误的。

这个问题的答案尤其是,在JGrasp中,删除相关的.gpj文件,然后使用相同的文件重新制作。它应该保存文件的更新版本,没有进一步的错误。再次感谢您,Fildor,提出了这个答案。

虽然它编译得很好,但它给出了一个错误,即语句是矛盾的。请您在UseCompany中标记第19行好吗?所以jgrasp认为有错误,但javac没有错误?@Teepeemm:基本上,似乎是这样。您知道JDK jgrasp在编译时使用的是什么吗?
public static void displayArray(ArrayList<Employee> list) //Displays array one line at a time
{                                                            //Specialized for Employee class
  for (int i=0;i<list.size();i++)
  {
     if((list.get(i)).getType() == 'T')
     {
        System.out.println("Name: " + (list.get(i)).getName() + "\tNo.: " + (list.get(i)).getNumber() + "\tType: Technician\tDepartment: " + ((Technician)(list.get(i))).getDepartment() + "\tClearance Level: " + ((Technician)(list.get(i))).getLevel());
     }
     else if((list.get(i)).getType() == 'S')
     {
        System.out.println("Name: " + (list.get(i)).getName() + "\tNo.: " + (list.get(i)).getNumber() + "\tType: Salesperson\tTerritory: " + ((SalesMan)(list.get(i))).getTerritory() + "\tTarget: " +((SalesMan)(list.get(i))).formattedTarget());
     }
  }
}
/**
* This is the superclass Employee.
* It contains the general information for SalesMan and Technician
*/
import java.io.*;

public class Employee implements Comparable, Serializable
{
private String name;            // Name of employee
private int number;         // Employee number of employee
char typeCode;   // What kind of employee is it

/**
* Constructor  to create the superclass
* @param nom Name of the employee
* @param number Employee number
*/
public Employee(String nom, int number )
{
    name = nom;
    this.number = number;
}

public char getType()
{
   return typeCode;
}

public int getNumber()
{
   return number;
}

public String getName()
{
   return name;
}

/**
* compareTo method for comparison of objects
* @param Employee object
* @return An integer to indicate comparison  
*/
public int compareTo(Object o)
{
    //Compare code
    return name.compareTo(((Employee)o).name);
}

/** toString method for printing */
public String toString()
{
  String employeeNum = Integer.toString(number);
  String str = new String("Name: " + name + "\nEmployee Number: " + employeeNum);
    return str;
}
}