Skip to main content
Inspiring
April 22, 2009
Question

array append error "Object of type class java.lang.String cannot be used as an array"

  • April 22, 2009
  • 2 replies
  • 4457 views

I have an array that I would like to continue adding items to. Setting the array and displaying the contents works fine but when I try to append I get the error message "Object of type class java.lang.String cannot be used as an array"  Should this be a structure? or do I have my looping in the wrong place?  The goal is to combine 200 arrays into the content variable so I can write a .csv file to the server. 

Here's the basics:

<cfset content= ArrayNew(1)>

run queries

<cfset content = "#q14.name#" &","& "#big[1]#" & "," & "#big[2]#" & chr(10)> 

(this part above displays correctly in a cfdump with the items from the query which looks like this

Category, Written communication, 10)

<cfloop index="k" from="1" to="5">

<cfset temp = arrayappend(content, "#q14.name# ,#big[1]#, #big[2]#" & chr(10))>

</cfloop>

I've also tried something as simple as <cfset ArrayAppend(content, "hello test")> which still gives the above error message.

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
April 30, 2009

Why not keep it as simple as

<cfloop index="k" from="1" to="5">
<cfset content = q14.name & "," & big[1] & "," & big[2] & chr(10)>
</cfloop>

ilssac
Inspiring
April 22, 2009

Here's the basics:

<cfset content= ArrayNew(1)>

This line create a one diminsional array named 'content'

<cfset content = "#q14.name#" &","& "#big[1]#" & "," & "#big[2]#" & chr(10)> 

This line overrides the array varaibale named 'content' with a string value converting it into a string variable.

<cfset temp = arrayappend(content, "#q14.name# ,#big[1]#, #big[2]#" & chr(10))>

This line tries to append an array element to the now converted string variable named 'content'

Message was edited by: Ian Skinner String Variable NOT String Array