Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

Object of type class java.lang.Boolean cannot be used as an array Error

I have a very frustrating problem with this cfc, it works as it is designed when updating a quantity when it is greater than 0 but the seccond that the quantity is set to zero i get the "Object of type class java.lang.Boolean cannot be used as an array".  what is really interesting is that it happens on two diffrent lines.  -- MARKED AS SUCH --

it seems as though the problem only occurs where the code loops thru the array, perhaps i've set some variable wrong, but even then it shouldnt work for any quantity.  

Thank you for any help in advance.  


<CFCOMPONENT>
  <!--- Initialize the cart's contents --->
  <!--- Because this is outside of any <CFFUNCTION> tag, --->
  <!--- it only occurs when the CFC is first created --->
  <CFSET This.CartArray = ArrayNew(1)>


  <!--- *** ADD Method *** --->
  <CFFUNCTION
    NAME="Add"
    HINT="Adds an item to the shopping cart">
    <!--- Two Arguments: ProductID and Quantity --->
    <CFARGUMENT NAME="ProductID" TYPE="numeric" REQUIRED="Yes">
    <CFARGUMENT NAME="Quantity" TYPE="numeric" REQUIRED="No" DEFAULT="1">

    <!--- Get structure that represents this item in cart, --->
    <!--- then set its quantity to the specified quantity --->
    <CFSET CartItem = GetCartItem(ProductID)>
    <CFSET CartItem.Quantity = CartItem.Quantity + Arguments.Quantity>
  </CFFUNCTION>  
 
 
  <!--- *** UPDATE Method *** --->
  <CFFUNCTION
    NAME="Update"
    HINT="Updates an item's quantity in the shopping cart">
    <!--- Two Arguments: ProductID and Quantity --->
    <CFARGUMENT NAME="ProductID" TYPE="numeric" REQUIRED="Yes">
    <CFARGUMENT NAME="Quantity" TYPE="numeric" REQUIRED="Yes">

    <!--- If the new quantity is greater than zero --->  
    <CFIF Quantity GT 0>
       <!--- Get structure that represents this item in cart, --->
       <!--- then set its quantity to the specified quantity --->
      <CFSET CartItem = GetCartItem(ProductID)>
      <CFSET CartItem.Quantity = Arguments.Quantity>
      <!--- If new quantity is zero, remove the item from cart --->
    <CFELSE>
      <CFSET This.Remove(ProductID)>
    </CFIF>
  </CFFUNCTION>  

 
  <!--- *** REMOVE Method *** --->
  <CFFUNCTION
    NAME="Remove"
    HINT="Removes an item from the shopping cart">
    <!--- One Argument: ProductID --->
    <CFARGUMENT NAME="ProductID" TYPE="numeric" REQUIRED="Yes">

    <!--- What position is this item occupying in the cart? --->
    <CFSET CartPos = GetCartPos(ProductID)>
   
    <!--- Assuming the item was found, remove it from cart --->
    <CFIF CartPos GT 0>
      <CFSET This.CartArray = ArrayDeleteAt(This.CartArray, CartPos)>
    </CFIF>
  </CFFUNCTION>  
 
 
  <!--- *** EMPTY Method *** --->
  <CFFUNCTION
    NAME="Empty"
    HINT="Removes all items from the shopping cart">
   
    <!--- Empty the cart by clearing the This.CartArray array --->
    <CFSET ArrayClear(This.CartArray)>
  </CFFUNCTION>
 

  <!--- *** LIST Method *** --->
  <CFFUNCTION
    NAME="List"
    HINT="Returns a query object containing all items in shopping cart.  The query object has three columns: ProductID, Quantity and Price."
    RETURNTYPE="query">

    <!--- Create a query, to return to calling process --->
    <CFSET q = QueryNew("ProductID,Quantity,Price,Name,Dosage,Count")>
   
    <!--- For each item in cart, add row to query --->
    <CFLOOP FROM="1" TO="#ArrayLen(This.CartArray)#" INDEX="i">      ------- FIRST ERROR HERE ------------
      <CFSET QueryAddRow(q)>
      <CFSET QuerySetCell(q, "ProductID",  This.CartArray[i].ProductID)>
      <CFSET QuerySetCell(q, "Quantity", This.CartArray[i].Quantity)>
        <CFSET QuerySetCell(q, "Price", This.CartArray[i].Price)>
        <CFSET QuerySetCell(q, "Name", This.CartArray[i].Name)>
        <CFSET QuerySetCell(q, "Dosage", This.CartArray[i].Dosage)>
        <CFSET QuerySetCell(q, "Count", This.CartArray[i].Count)>
    </CFLOOP>

    <!--- Return completed query --->    
    <CFRETURN q>    
  </CFFUNCTION>  


  <!--- Internal GetCartPos() Method --->
  <CFFUNCTION
    NAME="GetCartPos"
    RETURNTYPE="numeric"
    ACCESS="private">
    <!--- Argument: ProductID --->
    <CFARGUMENT NAME="ProductID" TYPE="numeric" REQUIRED="Yes">
   
    <!--- Get position, if any, of ProductID in cart query --->
    <CFSET CurrentArrayPos = 0>
    <CFLOOP FROM="1" TO="#ArrayLen(This.CartArray)#" INDEX="i">           ---------  SECCOND ERROR HERE ----------------
      <CFIF This.CartArray[i].ProductID EQ Arguments.ProductID>
        <CFSET CurrentArrayPos = i>
        <CFBREAK>
      </CFIF>
    </CFLOOP>    
   
    <!--- Return the position --->
    <CFRETURN CurrentArrayPos>
  </CFFUNCTION>  


  <!--- Internal GetCartItem() Method --->
  <CFFUNCTION
    NAME="GetCartItem"
    RETURNTYPE="struct"
    ACCESS="private">
    <!--- One Argument: ProductID --->
    <CFARGUMENT NAME="ProductID" TYPE="numeric" REQUIRED="Yes">
   
    <!--- Get the position of the item in This.CartArray --->
    <CFSET CartPos = GetCartPos(ProductID)>
   
    <!--- If item for this ProductID was found, we will return it --->
    <CFIF CartPos GT 0>
      <CFSET CartItem = This.CartArray[CartPos]>
    <!--- If item was not found, create new one and add to cart --->  
    <CFELSE>
        
        <cfquery name="Pricing" dataSource="Cart">
                    SELECT *
                  FROM DrugDetails
                  WHERE DetailID = #Arguments.ProductID#
        </cfquery>      
   
        <CFSET CartItem = StructNew()>
      <CFSET CartItem.ProductID = Arguments.ProductID>
      <CFSET CartItem.Quantity = 0>
        <CFSET CartItem.Price = '#Pricing.Price#'>
        <CFSET CartItem.Name = '#Pricing.Name#'>
        <CFSET CartItem.Dosage = '#Pricing.Dosage#'>
        <CFSET CartItem.Count = '#Pricing.Count#'>
      <CFSET ArrayAppend(This.CartArray, CartItem)>

      </CFIF>

    <!--- In either case, return the item --->
    <CFRETURN CartItem>
  </CFFUNCTION>  
 
</CFCOMPONENT>
0
R_Hos
Asked:
R_Hos
  • 6
  • 5
1 Solution
 
mrichmonCommented:
I do not see any reason why those lines would be causing an error with quantity of 0 - ar you sure taht is where the error is?
0
 
R_HosAuthor Commented:
yes.  wow.  its a relief to hear that i'm not the only one who cant figure out the problem
0
 
R_HosAuthor Commented:
additionaly, something i just noticed is that the empty method is not working which makes me think that its something in how i'm either setting up the array or using it...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrichmonCommented:
is it if you add an item of quantity 0 or if you remove items and the quantity ends up being 0 that the problem occurs?
0
 
mrichmonCommented:
Because this looks like the code from the CFWACK book and I know that that works since I used that as a starting point when writing my own shopping cart over - although that was almost 2 years ago when I wrote it, but it still works....
0
 
mrichmonCommented:
But technically you should never have a quantity of 0 since looking at the code the item should be removed here :

<!--- If the new quantity is greater than zero --->  
    <CFIF Quantity GT 0>
       <!--- Get structure that represents this item in cart, --->
       <!--- then set its quantity to the specified quantity --->
      <CFSET CartItem = GetCartItem(ProductID)>
      <CFSET CartItem.Quantity = Arguments.Quantity>
      <!--- If new quantity is zero, remove the item from cart --->
    <CFELSE>
      <CFSET This.Remove(ProductID)>
    </CFIF>


So I am not sure why a quantity of 0 would be causing this problem...
0
 
mrichmonCommented:
Do you have a sample URL where the problem is occuring?
0
 
R_HosAuthor Commented:
that's exactly where i got the base code from and i've modified it.  I could swear that sometime in the past i had checked that changing the quantity to 0 just removed it from the cart... now it drops the error.

If you go to...

www.purduebooks.com/rxonline/frontend/productsearch.cfm 

you can do a search for products or see a list of products alphabeticly.  add something to the cart and then set the quantity to zero and click 'update quantities' and you can see my problem first hand.  

thanks
0
 
mrichmonCommented:
Okay interesting - it is not 0 that is causing the error.  I also tried a negative quantity and that caused the error - and once I got the error even going back and entering a different amount or a different product would give me the error....

Let me play a bit more...
0
 
R_HosAuthor Commented:
once you get an error its stuck in the error until the session expires or till you delete the cookie.  i havnt seen the error with a positive number
0
 
fmediaCommented:
0
 
R_HosAuthor Commented:
sorry all, fell off ladder
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now