Solved

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

Posted on 2004-04-21
12
841 Views
Last Modified: 2013-12-24
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
Comment
Question by:R_Hos
  • 6
  • 5
12 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 10883210
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
 
LVL 5

Author Comment

by:R_Hos
ID: 10883246
yes.  wow.  its a relief to hear that i'm not the only one who cant figure out the problem
0
 
LVL 5

Author Comment

by:R_Hos
ID: 10883260
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10883275
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10883287
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10883307
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 35

Expert Comment

by:mrichmon
ID: 10883502
Do you have a sample URL where the problem is occuring?
0
 
LVL 5

Author Comment

by:R_Hos
ID: 10889594
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10890103
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
 
LVL 5

Author Comment

by:R_Hos
ID: 10890681
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
 
LVL 2

Accepted Solution

by:
fmedia earned 500 total points
ID: 10907449
0
 
LVL 5

Author Comment

by:R_Hos
ID: 10989080
sorry all, fell off ladder
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now