class java.lang.Boolean cannot be cast to class java.util.ArrayList

475 Views Asked by At

I'm trying to read an ArrayList of objects from a BinaryI/O but I keep getting the error "class java.lang.Boolean cannot be cast to class java.util.ArrayList (java.lang.Boolean and java.util.ArrayList are in module java.base of loader 'bootstrap')"

This is the code

public void readAdmin(){
     try{
         File file = new File("Administrators.dat");
         file.createNewFile();
         ObjectInputStream input = new ObjectInputStream(new FileInputStream("Administrators.dat"));
         ArrayList<Administrator> adms = (ArrayList<Administrator>) input.readObject(); 
         usercontroller.setAdmins(adms);

     }
     catch(IOException e){
         System.out.println("Input of administrator data error.");
     }
     catch (ClassNotFoundException cn){
         System.out.println("Administrator class not existent.");
     }

The line "ArrayList adms = (ArrayList) input.readObject();" seems to be the one causing the error when I call the "readAdmin" method in main.

Any ideas on how I can fix this?

0

There are 0 best solutions below