School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,404 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,625 people online right now. Registration is fast and FREE... Join Now!




ArrayInsertAt Error

 

ArrayInsertAt Error, Attempting to insert an array element; does not work

midasxl

28 May, 2009 - 05:58 AM
Post #1

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Greetings, and thanks for reading! I am attempting to insert an array element using Coldfusion ArrayInsertAt, but I keep getting the following error...

Error casting an object of type to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.

Here's the snippet...

CODE

<cfset arrUic=myRequest.Envelope.Body.XmlChildren><br />

<cfdump var="#arrUic#">

<cfoutput>
<p>Here is a loop of the above xml document object, extracting the xml children of envelope.body</p>
<ol>
<cfloop index="i" from="1" to="#ArrayLen(arrUic)#">
  <li>#arrUic[i]#</li>
</cfloop>
</ol>
</cfoutput>

<cfoutput>This array has #ArrayLen(arrUic)# child/children</cfoutput><br />

<cfoutput>Is this array empty? #ArrayIsEmpty(arrUic)#</cfoutput><br />

<cfset ArrayInsertAt(arrUic,1,35)>


Thank for any help!

User is offlineProfile CardPM
+Quote Post


Craig328

RE: ArrayInsertAt Error

28 May, 2009 - 12:56 PM
Post #2

New D.I.C Head
*

Joined: 13 Jan, 2008
Posts: 23



Thanked: 3 times
My Contributions
Your issue probably has to do with this line in your code:
CODE
<cfset arrUic=myRequest.Envelope.Body.XmlChildren>

...not playing nice with this:
CODE
<cfset ArrayInsertAt(arrUic,1,35)>


Now, that seems obvious given the error you're getting. However, to troubleshoot this, rather than doing the cfdump, try this:
CODE
<cfoutput>[#myRequest.Envelope.Body.XmlChildren#]</cfoutput>


Look at that output carefully. Is there a space between the outputted variable and the first square bracket? If so, you've run into something that gave me fits just a few days back. You're not really looking at the content of that variable (even though it looks like you are). You're looking at a structure that contains the variable...in this case, an array.

Try this:
CODE
<cfset arrUic=myRequest.Envelope.Body.XmlChildren.XmlText>
and see if that fixes it. Keep in mind that a ColdFusion array is different from a Javascript array is different from what looks like an array in XML. You may have to strip the individual variables out of the XML struct, reassemble them as an array and they try to manipulate that. Even if that doesn't do it, you need to concentrate your debug efforts on what you're getting out of the XML structure as that's almost certainly your issue.

Good luck!

QUOTE(midasxl @ 28 May, 2009 - 05:58 AM) *

Greetings, and thanks for reading! I am attempting to insert an array element using Coldfusion ArrayInsertAt, but I keep getting the following error...

Error casting an object of type to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.

Here's the snippet...

CODE

<cfset arrUic=myRequest.Envelope.Body.XmlChildren><br />

<cfdump var="#arrUic#">

<cfoutput>
<p>Here is a loop of the above xml document object, extracting the xml children of envelope.body</p>
<ol>
<cfloop index="i" from="1" to="#ArrayLen(arrUic)#">
  <li>#arrUic[i]#</li>
</cfloop>
</ol>
</cfoutput>

<cfoutput>This array has #ArrayLen(arrUic)# child/children</cfoutput><br />

<cfoutput>Is this array empty? #ArrayIsEmpty(arrUic)#</cfoutput><br />

<cfset ArrayInsertAt(arrUic,1,35)>


Thank for any help!


User is offlineProfile CardPM
+Quote Post

midasxl

RE: ArrayInsertAt Error

1 Jun, 2009 - 10:39 AM
Post #3

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Thanks for the reply. I tried the cfoutput as you suggested and this is what I got...

CODE

Complex object types cannot be converted to simple values.  
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag.

  
The error occurred in /usr/local/apache2/htdocs/ncdb_core/marks_test3.cfm: line 81

79 :
80 : <cfset arrUic=myRequest.Envelope.Body.getSubordinates.XmlChildren><br />
81 : <cfoutput>[#myRequest.Envelope.Body.getSubordinates.XmlChildren#]</cfoutput>



Not sure what this means. Thanks!


User is offlineProfile CardPM
+Quote Post

xheartonfire43x

RE: ArrayInsertAt Error

1 Jun, 2009 - 11:03 AM
Post #4

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
QUOTE(midasxl @ 1 Jun, 2009 - 10:39 AM) *

Thanks for the reply. I tried the cfoutput as you suggested and this is what I got...

CODE

Complex object types cannot be converted to simple values.  
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag.

  
The error occurred in /usr/local/apache2/htdocs/ncdb_core/marks_test3.cfm: line 81

79 :
80 : <cfset arrUic=myRequest.Envelope.Body.getSubordinates.XmlChildren><br />
81 : <cfoutput>[#myRequest.Envelope.Body.getSubordinates.XmlChildren#]</cfoutput>



Not sure what this means. Thanks!


That error just means that it is a complex variable (ie. structure,array,query, anything that is not just straight text) You need to do a dump of the array because...well it's an array.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:32PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month