weixin_42487516
愈不通
2019-01-04 20:47

为什么我用IO创建ObjectInSteram是会出现错误,并且报错一直报错在那一行

  • java
  • eclipse
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("d:\\练习\\a.txt"));
        ArrayList list1 = (ArrayList)ois.readObject();
        ArrayList<Student> listStu = new ArrayList<>();
        ArrayList<Teacher> listTc = new ArrayList<>();
        for (Object object : list1) {

            listStu.add((Student)object);
            listTc.add((Teacher)object);
        }
        System.out.println(listStu);
        System.out.println(listTc);
        ois.close();

为什么第一行总是在报错

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from Class<? extends Object[]> to Class<? extends Object[]>

    at java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1636)
    at java.lang.invoke.MethodHandle.asCollector(MethodHandle.java:999)
    at java.lang.invoke.MethodHandleImpl$AsVarargsCollector.<init>(MethodHandleImpl.java:460)
    at java.lang.invoke.MethodHandleImpl$AsVarargsCollector.<init>(MethodHandleImpl.java:454)
    at java.lang.invoke.MethodHandleImpl.makeVarargsCollector(MethodHandleImpl.java:445)
    at java.lang.invoke.MethodHandle.setVarargs(MethodHandle.java:1325)
    at java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:1670)
    at java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:1605)
    at java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:781)
    at java.lang.invoke.CallSite.<clinit>(CallSite.java:226)
    at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
    at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
    at java.io.ObjectInputStream.<clinit>(ObjectInputStream.java:3920)
    at IOTest.Test01.Test0_1.main(Test0_1.java:44)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换