array required, but ArrayList found

后端 未结 7 1556
执念已碎
执念已碎 2021-02-06 07:47

I have a ruby backround and im new to java i wrote a basic programm but somehow i get a error i cant fix! My code:

import java.util.ArrayList;

public class Musi         


        
相关标签:
7条回答
  • 2021-02-06 08:43

    Hey the problem is in this method

    public void returnFiles(){
            for(int i = 0; files.size() <= i; i++){
                System.out.println( i + ". Ist: " + files[i]);
            }
    
     }
    

    Precisely, on the

    files[i]
    

    You are trying to access your ArrayList instance variable as if it were a an Array. Just change that for

    files.get(i)
    

    You have to use the method get(int index) from the ArrayList<> class.

    0 讨论(0)
提交回复
热议问题