Skip to main content
Participant
January 13, 2012
Question

coldfusion Error : Object of type class coldfusion.runtime.Struct cannot be used as an array

  • January 13, 2012
  • 2 replies
  • 3855 views

Hi,

I'm getting the above error when accessing  the below code and most strange part is I could only manage to get this error one out of 50 times

CFM file

------------

                            <cfset aDropDown = application.GuestingController.Main("getGuestingCampaignDropDown", questions.questionID) />

                            <select name="questionAnswerID_#totalQuestions#" id="questionAnswerID_#totalQuestions#_PopUp" class="text">

                                <option value="" selected="">Select...</option>

                                <CFLOOP ARRAy="#aDropDown#" index="answer">

                                    <option value="#answer.dropDownID#">#answer.dropDownText#</option>

                                </cfloop>

                            </select>

                            <input type="hidden" name="questionAnswerText_#totalQuestions#" value="" />

                        

CFC

------

<cffunction name="getGuestingCampaignDropDown" access="public" returntype="Array" output="false">

        <cfargument name="questionID" required="true" type="numeric">

        <cfscript>

            var aAnswers = ArrayNew(1);

            var stAnswers = StructNew();

            var qrAnswers = '';

            var i = 1;

        </cfscript>

        <cfstoredproc procedure = "getGuestingCampaignDropDown" dataSource = "#application.ds#">

            <cfprocparam type = "IN" CFSQLType = "CF_SQL_INTEGER" value = "#arguments.questionID#">

            <cfprocresult name = "qAnswers" >

        </cfstoredproc>

        <cfscript>

            for(i=1; i lte qAnswers.recordcount; i++){

                stAnswers = StructNew();

                stAnswers.dropDownID = qAnswers.guestingQuestionDropDownID;

                stAnswers.dropDownText = qAnswers.dropDownText;

                stAnswers.sequence = qAnswers.sequence;

                arrayAppend(aAnswers,stAnswers);

            }

        </cfscript>

        <cfreturn aAnswers />

    </cffunction>

Can anyone please suggest me ,what is wrong with the above code.

Thanks in Advance

Nik

    This topic has been closed for replies.

    2 replies

    Inspiring
    January 14, 2012

    Put a try/catch around the erroring code, and dump out the variable that you're expecting to be an array but CF thinks is a struct.  The contents of the variable should give you a clue as to what's going on.

    --

    Adam

    Inspiring
    January 13, 2012

    It might be due to a mismatch in variable names in your function.  You initialize variable qrAnswers and return your sproc results to variable qAnswers.

    Or it might be something else.