简体   繁体   中英

How do you navigate an array of image file objects in Java?

I am tasked to create navigation buttons for a simple image processing application, that navigate through a folder containing images. I am required to create an array of file objects of a selected folder.

The buttons have to be next and previous buttons, that navigate the next image within the array of file objects. After the last image within the folder was reached, the next button has to loop to the first image and vice versa with the previous button.

I tried declaring an int[] array of the length of the number of files contained within a folder using the listFiles() method, but I received the error: cannot find symbol :

int[] file = new int[("/pictures").listFiles().length];

What would I need to do in order to be able to create an array of file objects of the length of the total number of files, which I would be able to navigate using buttons?

Your problem is calling listFiles on a String , rather than File object. Try to modify your code as follows:

int[] file = new int[new java.io.File("/pictures").listFiles().length];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM