Solved

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

Posted on 2004-04-21
12
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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
 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

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 …
What You Need to Know when Searching for a Webhost Provider
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

739 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