-4

I am having trouble converting an object to an array. I have already searched for this problem but none of it was a solution for me.

I am having an error of

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.awt.shell.Win32ShellFolder2 cannot be cast to [Ljava.lang.String;

this is my code:

 for (int i=0; i < list.getModel().getSize(); i++) {
                Object item = list.getModel().getElementAt(i);
                System.out.println("Item = " + item);   

                //String[] srcFiles = (String[]) item;

                File finalFile = new File(srcFiles[i]);
                FileInputStream fis = new FileInputStream(finalFile);

How can I convert Object item to a String array?

1 Answers1

1

As sun.awt.shell.Win32ShellFolder2 is a subclass of File you can just write:

Object item = list.getModel().getElementAt(i);
System.out.println("Item = " + item);   
FileInputStream fis = new FileInputStream((File)item);
Pavlo Viazovskyy
  • 927
  • 5
  • 12