user2188377
user2188377

Reputation: 1

The type of expression must be an array but resolved to list<string>

I am creating a list of string fields and storing in a array list. Now when passing that array list to the array I am getting the following error :

The type of expression must be an array but resolved to list

List<String> fields = new ArrayList<String>();
        fields.add("_raw");
        //fields.add("_time");
        fields.add("host");
        fields.add("sourcetype");
        fields.add("source");
        jobRes.setFieldList(fields[]);
        jobRes.setOffset(2500);

Upvotes: 0

Views: 890

Answers (2)

withoutIf
withoutIf

Reputation: 128

(Sorry for the addtl answer, I can't flippin' comment) On second glance, I'd imagine this is Java, since C# doesn't have an ArrayList that allows type assignments (I don't think, anyway). The above is actually correct in Java, since ArrayList inherits from abstract list. The reason for this is usually to convert to simplify iteration/conversion. ArrayList already has an add method, so it looks like the cast is there only to enable a different cast that isn't being performed... :)

Upvotes: 0

withoutIf
withoutIf

Reputation: 128

This is a little vague. Is this java? C#? At any rate, I'd bet the problem is in your cast. I'd try something like:

jobRes.setFieldList(fields.ToArray(new String[fields.Size()])

This will actually pass an array.

Upvotes: 2

Related Questions