Solved

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

Posted on 2004-04-21
12
851 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

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

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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