Skip navigation
daveioi
Currently Being Moderated

You have attempted to dereference a scalar variable of type class java.lang.String as a structure wi

Mar 25, 2010 2:59 PM

You  have  attempted to dereference a scalar variable of type class  java.lang.String as a  structure with members

Hi

 

 

I receive the error in the title bar as a result of the following code but I can't see what I'm doing wrong:

 

<cfcomponent hint="sets background colour to help users see where they are during booking">

 

<cffunction name="cellcolour" returntype="struct">
<cfargument name="progressstage" type="string" required="true">
<cfset var stagecol="StructNew()">

 

<cfset oncolour="red">
<cfset offcolour="white">

<cfswitch expression="#progressstage#">
<cfcase value="progressstage1">
<cfset stagecol.colour1="#oncolour#">
<cfset stagecol.colour2="#offcolour#">
<cfset stagecol.colour3="#offcolour#">
<cfset stagecol.colour4="#offcolour#">
<cfset stagecol.colour5="#offcolour#">
</cfcase>

 

........... etc

 

Thew line where the error occurs is <cfset stagecol.colour1="#oncolour#">.

 

Thanks in advance for any advice

 

Dave

 
Replies
  • Currently Being Moderated
    Mar 25, 2010 3:25 PM   in reply to daveioi

    1. Are you using cftry/catch in our component? In some CF verison (at least), var scoped variables couldn't be referenced in cfcatch block.

    2. What is your function returning? Is it a structure? Try removing the returntype attribute of the function.

    3. Double check for overlapping variable names - try to change your variable names in the function and check if that helps.

     

    And P.S. <cfset stagecol.colour1="#oncolour#"> is better and clearer written as <cfset stagecol.colour1 = oncolour>

    Never use pound signs until you're outputting something, or dynamically evaluating a variable name.

     

    -Fernis

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2010 3:55 PM   in reply to daveioi
    <cfset var stagecol="StructNew()">

     

    Look more closely at that line of code.

     

    What's wrong with it?

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2010 10:40 PM   in reply to Adam Cameron.
    <cfset var stagecol="StructNew()">

    Those cannot be seen by the human eye!

     

    ...Which is exactly why the habit of using extra "#quotes#" is shooting oneself in the leg.

     

    -Fernis

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2010 10:34 AM   in reply to daveioi

    No worries mate.  We've all done it.

     

    --

    Adam

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points