tags:

views:

128

answers:

2

How can i send a files which stored in array to other class? I have tried this code but isnt working.

public class abc {
    ....
    String [] indexFiles = new String[100];

    public abc (){
       indexFiles [0]=image1.txt;
       indexFiles [1]=image1.txt;
       .... 
       draw = new drawing (indexFiles(0)); // I got error in this code
       draw = new drawing (indexFiles.get(0)); // I also tried this code but it give me error as well.       
    }

}
+2  A: 

Use

indexFiles[0]
Frank Krueger
oh! how can i missed that [] ....thanks Frank :-)
Jessy
+4  A: 

Does your drawing class take an array of strings, or just a single string?

If it takes an array, use this:

draw = new drawing(indexFiles);

If it takes a single string, use this:

draw = new drawing(indexFiles[0]);

To access a single value in an array, you use the [] brackets, not parentheses.

Just a side note: The "get(0)" method is used for collections like ArrayList:

List<String> stringList = new ArrayList<String>();
stringList.add("MyString");
System.out.println(stringList.get(0));
Andy White